GTour Service

The GTourService is registered as a singleton service and can only have one active tour started at any time. When the StartTour method is called while there is an existing tour active, the first tour will be stopped first. Depending on what step the tour is on, this can be either TourCompleted or TourCanceled. If the tour is on the last step the TourCompleted will be called, if not the TourCanceled will be called. The service is registered in the DI Container on startup. See the example below to register the service.


        public void ConfigureServices(IServiceCollection services)
        {
            ...
            services.UseGTour();
            ...
        }
    

Methods

The GTourService has the following methods available and the tour can be controlled from this point. This is especially helpful when navigating from custom content in the tour steps.

  • RegisterTour(Abstractions.IGTour gTour) This is called internally and will automatically be called once a tour is included on a razor page.
  • StartTour(string tourId, string startStepName = default) Tries to start a tour with the given name and optionally the first step of the tour
  • StartTour(Abstractions.IGTour gTour, string startStepName = default) Tries to start a tour with the interface reference and optionally the first step of the tour
  • StopTour() Stops the currently active tour. If the Tour is on the last step, the tour will be completed. If not it will be canceled
  • CancelTour() Cancels the current active tour
  • PreviousStep() Navigates to the previous step in the active tour if there is a step prior
  • GoToStep(string stepName) Navigates to the step if it exists
  • CompleteTour() Completes the tour
  • DeRegisterTour(Abstractions.IGTour gTour) This is called internally and will automatically be called once a tour component is disposed.

 <GuidedTour ...>
 <GuidedTourStep ...>
     <ChildContent ...>
        ...
     </ChildContent>
     <FooterContent>
            ...
         <button class="btn" @onclick="@(() => GTourService.CompleteTour())">Complete</button>    
     </FooterContent>
 </GuidedTourStep>
</GuidedTour>

    

    ...

    [Inject]
    private GTour.Abstractions.IGTourService GTourService { get; set; }

    private async Task StartTour() 
    {
        ...
        await GTourService.StartTour("TourName", "startAtStep");    
        ...
    }
    

Events

The GTourService has a few events that can be used to help drive the tour as well as assist in logging output.

  • OnTourRegistered
  • OnTourDeRegistered
  • OnTourStarting
  • OnTourStarted
  • OnTourCanceling
  • OnTourCanceled
  • OnTourCompleting
  • OnTourCompleted

@implements IDisposable
    
    ...

    protected override void OnInitialized()
    {
        base.OnInitialized();
        GTourService.OnTourRegistered += OnTourRegistered;
    }

    private void OnTourRegistered(GTour.Abstractions.IGTourService sender, GTour.Abstractions.IGTour tour)
    {
        Console.WriteLine($"Tour with name {tour.TourId} registered");
    }

    public void Dispose()
    {
        GTourService.OnTourRegistered -= OnTourRegistered;
    }

    
An unhandled error has occurred. Reload 🗙