Code I was using before...
Binding binding_isChecked = new Binding("IsChecked");Code I'm using now...
binding_isChecked.ElementName = "cbCheckAll";
binding_isChecked.Mode = BindingMode.OneWay;
DependencyProperty property_isChecked = CheckBox.IsCheckedProperty;
Binding binding_isNotChecked = new Binding("IsChecked");
binding_isNotChecked.ElementName = "cbCheckAll";
binding_isNotChecked.Mode = BindingMode.OneWay;
BoolToOppositeBoolConverter boolConverter = new BoolToOppositeBoolConverter();
binding_isNotChecked.Converter = boolConverter;
DependencyProperty property_isEnabled = CheckBox.IsEnabledProperty;
cb.SetBinding(property_isChecked, binding_isChecked);
cb.SetBinding(property_isEnabled, binding_isNotChecked);
cb.Checked += delegate
{
foreach (CheckBox checkBoxInStackPanel in sp.Children)
{
if (!checkBoxInStackPanel.Content.Equals(cbCheckAllContent))
{
checkBoxInStackPanel.IsChecked = true;
checkBoxInStackPanel.IsEnabled = false;
}
}
};
cb.Unchecked += delegate
{
foreach (CheckBox checkBoxInStackPanel in sp.Children)
{
if (!checkBoxInStackPanel.Content.Equals(cbCheckAllContent))
{
checkBoxInStackPanel.IsChecked = false;
checkBoxInStackPanel.IsEnabled = true;
}
}
};
1 comment:
Here's the code for the BoolToOppositeBoolConverter class used in the post above:
private class BoolToOppositeBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{ return !(bool)value; }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{ return !(bool)value; }
}
Post a Comment