Radio button navigation

Wizard for WPF Forum

Posted 15 years ago by David V
Version: 4.5.0486
Avatar
Hi-- I am getting started with the Wizard control, and I have created a wizard page with two radio buttons and standard (Next, Previous) navigation buttons. The intent is for the user to click on a radio button to select what they want to do, then click the Next button to continue. When they click the Next button, the page they go to is determined by which radio button they clicked. Note that the page should not advance until the Next button is clicked.

Is there a simple example that shows how to so this, preferably in XAML? I'd like to be able to do it without event-handling in code-behind. Thanks!

David Veeneman
Foresight Systems

Comments (4)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi David,

Take a look at our main Features demo's MainControl.xaml. In that we do this all in XAML.

Scroll down to where demoPathPage is defined. We have a ListBox that looks like a radio button list. Each list box item has a Tag with a string name of another page.

There is a binding on the ListBox to set the WizardPage's NextPage property to the value of the currently selected item's Tag. Thus everything is achieved 100% in XAML.


Actipro Software Support

Posted 15 years ago by David V
Avatar
Thanks--very helpful, I'll check that out.
Posted 15 years ago by David V
Avatar
For those using MVVM architecture, there is another solution that avoids code-behind in the wizard. It involves binding the radio buttons to a command that changes the NextPage property of the wizard page. Here is the procedure to implement it.

1) In your view model for the wizard, create a 'SetNextPage' ICommand property, and a 'NextPage' bindable string property. The ICommand class will need a reference to the view model.

2) The Execute() method of the ICommand should convert the parameter passed into it into a string and set the view model's NextPage property to that value.

3) In the XAML for the page with your radio buttons, add a command binding to each radio button that binds the button to the SetNextPage command in the view model. Then add a CommandParameter property that passes the name of the page that should be navigated to if that button is pressed.

4) Still in XAML, bind the NextPage property of the wizard page that has the radio buttons to the NextPage property of the view model.

When a radio button is pressed, the SetNextPage command will change the NextPage property of the view model to the page passed as the CommandParameter by the radio button. Since the NextPage property of the radio button page is bound to that view model property, the change is propagated back to the wizard page, and the wizard will navigate to the desired page when the Next button is clicked.

Just one more reason why I love the MVVM pattern.

[Modified at 04/07/2009 02:22 PM]
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the helpful post David. I'm sure other customers using MVVM will appreciate it.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.