Reputation: 21260
I use NavigationWindow
, on the first screen the user should select some radio button
and press next to the next screen.
Regarding to the radio button
selection on the next screens I should put all the relevant pictures and give all the buttons there their relevant functionality .
What is the right way to do so ?
In winforms
i would pass in the next screen contractor the radio button value and via if else statements do everything in the contractor and in the event functions .
I learned already about data binding .
Can you explain step by step how i should implement this thing ....
Upvotes: 2
Views: 113
Reputation: 96702
The right approach really depends on the complexity of the problem. A fairly simple way to go about it is to create a view model object at application startup and put it in the application's resource dictionary, and then have the constructor of every Page
set the DataContext
to that object. You can then bind the controls in your pages to properties of this object, which essentially is the data context of the entire set of pages.
For instance, on page 1 you might have a set of radio buttons bound to a set of boolean properties in the view model. Page 2's controls could be styled to display information based on these properties' settings, e.g.:
<DockPanel Visibility="Collapsed">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Style.Triggers>
<DataTrigger Binding="{Binding BooleanProperty1}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
<!-- controls that should appear if BooleanProperty1 is True go here -->
</DockPanel>
There are a lot of scenarios that this won't work for, but in the relatively simple case of a multipart wizard, it's likely to be what you want.
An unrelated note, but since you brought it up: binding to radio buttons has got an ugly little design issue. If you bind the IsChecked
properties of three radio buttons in a group to three boolean properties, and then click on each button, you'll find that the bound values in the source are all set to True. This happens because when a radio button in a group gets checked, it explicitly clears the IsChecked
value on the other buttons in the group, and that breaks the binding. There are (sort of) good reasons for this, but it's something you can spend a lot of time on if you don't know it's there. The way to implement bound radio buttons is to put each one into its own group and handle the toggling in your view model, e.g.:
<RadioButton Group="BooleanProperty1" IsChecked="{Binding BooleanProperty1, Mode=TwoWay}"/>
<RadioButton Group="BooleanProperty2" IsChecked="{Binding BooleanProperty2, Mode=TwoWay}"/>
<RadioButton Group="BooleanProperty3" IsChecked="{Binding BooleanProperty3, Mode=TwoWay}"/>
public bool BooleanProperty1
{
set
{
if (value != _BooleanProperty1)
{
_BooleanProperty1 = value;
if (value)
{
BooleanProperty2 = false;
BooleanProperty3 = false;
}
OnPropertyChanged("BooleanProperty1");
}
}
}
Upvotes: 1