I have a window with two checkboxes bound to properties of class Options:
public class Options
{
public bool Option1 { get; set; }
public bool Option2 { get; set; }
public bool AnotherOption { get; set; }
}
xaml:
<CheckBox
Content="Option #1"
IsChecked="{Binding Path=Option1}"/>
<CheckBox
Content="Option #2"
IsChecked="{Binding Path=Option2}"/>
Also I have third checkbox that should be disabled when the other two are unchecked. To achieve this I used multibinding:
<CheckBox
IsChecked="{Binding Path=AnotherOption}"
Content="Another option">
<CheckBox.IsEnabled>
<MultiBinding Converter="{StaticResource MultiValueLogicalOrConverter}">
<Binding Path="Option1"/>
<Binding Path="Option2"/>
</MultiBinding>
</CheckBox.IsEnabled>
</CheckBox>
converter:
public class MultiValueLogicalOrConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values.Cast<bool>().Any(value => value);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
This seems to work fine. But sometime it was pointed out that Option's properties are not dependency properties and don't fire PropertyChanged event, so I cannot explain why this works. Any ideas?