This is a migrated thread and some comments may be shown as answers.

How to "skip" certain pages in RadWizard's SelectionChanging event

1 Answer 566 Views
Wizard
This is a migrated thread and some comments may be shown as answers.
Travis
Top achievements
Rank 1
Iron
Travis asked on 01 Nov 2018, 08:08 PM

I have a very simple wizard that contains 3 pages. The first page should always be shown and is the starting point for the wizard. Now, I have the SelectionChanging event hooked up on the wizard to perform some validation before allowing the user to move on. However, here is where the trick comes in:I would like to be able to skip step two if certain conditions are met and move the user directly to the last page of the wizard. Likewise, as long as this condition is met, if the user then clicks Back to go to the previous step, I'd like to take the user to the first page in this scenario.

I cannot remove the second page of the wizard because this page may be needed in some cases depending on whether the specified criteria is met. Apparently, setting the Wizard's SelectedPage property to the page I want isn't the right way to do it because it puts the wizard into an infinite loop where it keeps going between the first page and the last page because when I set the SelectedPage to the last page, the SelectionChanging event is raised again, but this time with the direction saying Backward which gets the wizard to go back to the first page since the OldPage is now the last page and the direction is Backward and the criteria for skipping the middle step is met, the SelectedPage is set back to the first page which raises the SelectionChanging event with the direction Forward and the OldPage being the first page... and round and round we go.

I'm looking for a solution that doesn't require me to add or remove pages to the collection on the fly and doesn't briefly navigate to the second page in a fashion that it creates a "stutter" to the user where it's obvious that the software is simulating the user clicking the next button when the second page is active.

 

TIA.

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 05 Nov 2018, 08:30 AM
Hello Travis,

To achieve your requirement you can use the Next and Previous events of the RadWizard control. There you can set the SelectedPage property manually without worrying about the loop. Here is an example in code:
private void RadWizard_Next(object sender, NavigationButtonsEventArgs e)
{           
    Dispatcher.BeginInvoke(new Action(() => {
        this.radWizard.SelectedPage = this.radWizard.WizardPages[2];
    }));
}
Note that using the Dispatcher to delay the SelectedPage settings is important. This is because the event is fired before the SelectedPage is set and you setting will get overridden by the internal code of the control.

I hope this helps.

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Timothy J
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 17 Dec 2022, 06:32 PM

Any way to accomplish this using an MVVM pattern where the VM does not have access to the SelectedPage?

I have attempted to set the SelectedPageIndex of the event args, but that doesn't seem to work.

Martin Ivanov
Telerik team
commented on 21 Dec 2022, 02:55 PM

The SelectedPage is a DependencyProperty, so you should be able to data bind it to a property in your view model. For the Next event, you can forward this to your view model, using the EventToCommandBehavior. To use a dispatcher in the view model, you can use App.Current.Dispatcher static property. I hope this idea helps.
Tags
Wizard
Asked by
Travis
Top achievements
Rank 1
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or