I'm trying to express an enumeration property in my view-model as a set of radio buttons in my view. So far, so good; I can express that with a two-way MultiBinding
:
(rb1.IsChecked, rb2.IsChecked, rb3.IsChecked) <-> vm.Value
The multi-binding used here would feature a multi-converter that converts between (bool, bool, bool) <-> MyValue
; obviously, one of the (three) allowable values of the MyValue
type is chosen based on which bool
is true
, and vice-versa.
This is already a bit inconvenient, though: I cannot define that binding in my view's Xaml, as multi-bindings have to be defined from the side of the single value. Hence, I have to define the multi-binding in code-behind and use SetBinding
set it on my view model's Value
property.
Now, the issue that I'm stuck at is that I'm not just binding one set of radio buttons to that value, but two. Hence, my bindings would have to look like this:
(rbA1.IsChecked, rbA2.IsChecked, rbA3.IsChecked) <-> vm.Value <-> (rbB1.IsChecked, rbB2.IsChecked, rbB3.IsChecked)
The problem is that I cannot use SetBinding
to connect several bindings to vm.Value
at a time.
Solutions that I have tried so far are:
(rbA1.IsChecked, rbA2.IsChecked, rbA3.IsChecked, rbB1.IsChecked, rbB2.IsChecked, rbB3.IsChecked) <-> vm.Value
. The problem with this solution is that if one of the radio buttons (say, rbB2
) is checked, I have no way of telling whether rbA2
(unchecked) or rbB2
(checked) has the "new, correct" value.SelectedIndex
property. This property can then be conveniently bound to my vm.Value
property from all instances of my radio group control. While feasible, it requires writing a new control class and I wonder whether this is the only way in WPF.rbB1
to rbA1
, rbB2
to rbA2
, and so on, and using a multi-binding between my vm.Value
and the first set of radio buttons only, I would achieve the desired effect, but I don't like the notion of having a "master radio group". It would be abusing GUI elements for data transfer.Bind VMEnum to each RadioButton seperately(use single two-way binding). Each binding should have CommandParameter it's enum. Like:
<RadioButton IsChecked="{Binding VMEnum, Converter={StaticResource EnumConverter}, ConverterParameter={Enums:VMEnums.FirstRadioButtonGroupA}}" />
In the converter,