添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
< Style x:Key =" ch" TargetType =" CheckBox" > < Style.Triggers > < DataTrigger Binding =" {Binding ElementName=check2, Path=IsChecked}" Value =" False" > < Setter Property =" IsChecked" Value =" True" / > < /DataTrigger > < /Style.Triggers > < /Style >
And assign this style to a checkbox, lets say CheckBox1 by doing in this way :
< checkbox name =" check1" style =" {StaticResource ch}" / >
What this trigger does is that, it will check the value of Checkbox2's IsChecked property. If its false, then check1's IsChecked value will be true(like you wanted it to be inversed).
If you don't want the values to be inversed then, it can be down straight away in check1 by doing this :
< checkbox name =" check1" ischecked =" {Binding ElementName=check2, Path=IsChecked}" / >
Hope it helped! If you want to bind two check boxes, you completely defeat the purpose of this control. It is designed to represent independent option. You're trying to mimic behavior of radio button. This is bad! And your user will be confused.
Another way to do it is to extend the CheckBox class and override the checked property to return the inverse. Something like
class InverseCheckBox : CheckBox new public bool Checked get { return !base.Checked; } set { base .Checked = !value; } I haven't rigorously tested this solution, and am unsure of any side effects, but I hope someone finds this useful :)
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •