Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use a value-converter that reverts the boolean value:</p> <p>With that converter, bind one Checkbox.IsChecked-property to the boolean value without the converter and one CheckBox.IsChecked-property with the converter. This should do the trick.</p> <p>Here the code for such a converter. I have copied it from <a href="http://www.codeproject.com/KB/WPF/OppositeBoolConverter.aspx" rel="noreferrer">here</a> and added some lines of code. There you will find more information about.</p> <pre><code>public class BoolToOppositeBoolConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture) { if (targetType != typeof(bool)) { throw new InvalidOperationException("The target must be a boolean"); } if (null == value) { return null; } return !(bool)value; } public object ConvertBack(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture) { if (targetType != typeof(bool)) { throw new InvalidOperationException("The target must be a boolean"); } if (null == value) { return null; } return !(bool)value; } } </code></pre> <p>To use it, declare it in the resource-section.</p> <pre><code> &lt;local:BoolToOppositeBoolConverter x:Key="BoolToOppositeBoolConverter_ValueConverter"/&gt; </code></pre> <p>And the use it in the binding as a static resource:</p> <pre><code>&lt;CheckBox IsChecked="{Binding YourProperty}" /&gt; &lt;CheckBox IsChecked="{Binding YourProperty,Converter={StaticResource BoolToOppositeBoolConverter_ValueConverter}}" /&gt; </code></pre> <p>Please note, the converter is only a simple example. Implement it neatly if you want to use it in productive code. I have not tested it. Make a comment if its not working.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload