If you want to solve this via Bindings (and you should), you need a MultiBindingConverter
that returns true
as long as one of the values is true
(boolean OR):
public class BooleanOrConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
foreach (object value in values)
{
if (value is bool && (bool) value)
return true;
}
return false;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return Enumerable.Repeat(DependencyProperty.UnsetValue, targetTypes.Length).ToArray();
}
}
Definition:
<Window.Resources>
<local:BooleanOrConverter x:Key="OrConverter"/>
</Window.Resources>
Usage:
<RadioButton x:Name="RadioButtonSource" GroupName="rButton" Content="A" Grid.Column="4"/>
<RadioButton x:Name="RadioButtonToken" GroupName="rButton" Content="B" Grid.Column="4"/>
<RadioButton x:Name="RadioButtonII" GroupName="rButton" Content="C" Grid.Column="4"/>
<RadioButton x:Name="RadioButtonUkey" GroupName="rButton" Content="D" Grid.Column="4"/>
<ComboBox Grid.Column="5" Width="120" Height="30">
<ComboBox.IsEnabled>
<MultiBinding Converter="{StaticResource OrConverter}">
<Binding ElementName="RadioButtonSource" Path="IsChecked"/>
<Binding ElementName="RadioButtonToken" Path="IsChecked"/>
<Binding ElementName="RadioButtonII" Path="IsChecked"/>
<Binding ElementName="RadioButtonUkey" Path="IsChecked"/>
</MultiBinding>
</ComboBox.IsEnabled>
</ComboBox>
This way, as soon as any of the RadioButtons
's IsChecked
properties becomes true
, the ComboBox
is enabled. If you reset the RadioButton
s, it get's disabled again.