[英]Binding a button's IsEnabled property to 2 checkbox IsChecked properties in XAML
I would like to enable a button when either of the 2 check boxes are checked. 我想在选中2个复选框中的任何一个时启用按钮。 When neither of the check boxes are checked, the button should be inactive(IsEnabled = false)
如果未选中任何复选框,则该按钮应处于非活动状态(IsEnabled = false)
It is possible to bind like this. 可以像这样绑定。
IsEnabled="{Binding ElementName=CheckBox Path=IsChecked}"
IsEnabled =“{Binding ElementName = CheckBox Path = IsChecked}”
But it works only for a single checkbox. 但它仅适用于单个复选框。 I want to bind both the check boxes IsChecked properties to the IsEnabled property of button in XAML itself.
我想将复选框IsChecked属性绑定到XAML本身的按钮的IsEnabled属性。 (I know how to do using property changed in code)
(我知道如何在代码中使用属性更改)
I tried using Multi triggers. 我尝试使用Multi触发器。
<Button.IsEnabled>
<MultiBinding>
<MultiBinding.Bindings> <Binding ElementName="BlankmeasurementCheckBox" Path="IsChecked"/>
<Binding ElementName="MeasurementCheckBox" Path="IsChecked"/>
</MultiBinding.Bindings>
</MultiBinding>
</Button.IsEnabled>
But it doesn't seem to help. 但它似乎没有帮助。 Could you please help me out?
你能帮帮我吗? Thanks in advance.
提前致谢。
You can make use of MultiDataTrigger
here. 您可以在此处使用
MultiDataTrigger
。
Here is the sample code: 以下是示例代码:
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<CheckBox Name="cbSampleYes" Content="Yes" />
<CheckBox Name="cbSampleSure" Content="I'm sure" />
<Button HorizontalAlignment="Center" Margin="0,20,0,0">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Content" Value="Verified" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=cbSampleYes, Path=IsChecked}" Value="False" />
<Condition Binding="{Binding ElementName=cbSampleSure, Path=IsChecked}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Content" Value="Unverified" />
<Setter Property="IsEnabled" Value="False" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.