Making a Wizard in Silverlight + Xaml

2019-07-31 02:55发布

问题:

I have a Silverlight application and I am trying to make each step of a wizard in XAML files, instead of hard-coded C#.

The problem is that I don't understand how I am going to switch between them after click on next button of each screen.

What is the best way to do this? I saw some tutorials on the internet about XAML dynamically loaded but none of them seem to work with me :/

回答1:

Use a ChildWindow as your parent window. Then create multiple UserControls which will be framed in the content of the parent window. In the code-behind of the parent window, load the user controls into a list and set the visibility to 'Collapsed' for all of them but the first. When the user presses the Next/Prev buttons, pull the appropriate UserControl from the list (keep track of the current index) and make it 'Visible' while making the current control 'Collapsed'.

All of your navigation code will be in the parent window, but the parent window won't be concerned about the content of the wizard steps itself.

Each UserControl can be coded in XAML as a separate control so you still maintain a separation of the control from your wizards navigation logic.

You can then create a class type that will hold all of the options for the various wizard controls. Pass a reference to an object instance to each of the controls for them to update. When you get to the end of the wizard, your option object should maintain the state of all the wizard steps and the parent window can return that to the application.



回答2:

I would suggest looking into the Silverlight Navigation Framework. It allows you to use "urls" to navigate between "pages" (which are your XAML user controls). It also also users to use the back and forth buttons in the browser, which may or may not be something you want to allow.

There is a VS 2010 template when you choose New Project, Silverlight, "Silverlight Navigation Application" that will help get you started.