Reputation: 65
I'm working on WPF (XAML) using the designer (very newbie) and C# as backing code.
I need to be able to have a few "pages" of Radio Buttons in the same group (i.e. clicking on item A on page 1 then clicking on B on page 2 should deselect A on page 1).
How would I go about doing this?
Thank you!
Note that the "buttons" are actually just radio buttons above images.
Upvotes: 2
Views: 278
Reputation: 61349
First, I would NOT recommend doing this. As a user, I would be very confused/surprised if my selections on one page affected a selection on a previous one.
As to how to accomplish it, I will assume you are using MVVM (as you should be in WPF). First, the ViewModel for each page needs to have a reference to the same backing property in the Model. In other words, your Model has a property like (where MyRadioSelection is some enum you are binding to):
public MyRadioSelection GlobalSelection {get; set;}
and your view models have:
public MyRadioSelection UserSelection
{
get {return Model.GlobalSelection;}
set
{
Model.GlobalSelection = value;
OnPropertyChanged(UserSelection);
}
}
Then you just need a ValueEquals converter (from this answer), bind all your radio buttons to the enum, and you should be good to go!
Please let me know if you would like a piece explained further. Also, posting your existing code would help improve this answer. Also note that your Model may need some way of notifying the ViewModels of external (another ViewModel's) changes to the backing property. You could approach this from several directions, but just implementing INotifyPropertyChanged and listening to it in the ViewModel would work.
Upvotes: 2