gpt4 book ai didi

wpf - 将按钮的 IsEnabled 属性绑定(bind)到 XAML 中的 2 个复选框 IsChecked 属性

转载 作者:行者123 更新时间:2023-12-03 10:22:39 29 4
gpt4 key购买 nike

我想在选中 2 个复选框中的任何一个时启用一个按钮。
当两个复选框均未选中时,按钮应处于非事件状态(IsEnabled = false)

可以这样绑定(bind)。

IsEnabled="{Binding ElementName=CheckBox Path=IsChecked}"



但它仅适用于单个复选框。我想将复选框 IsChecked 属性绑定(bind)到 XAML 本身中按钮的 IsEnabled 属性。 (我知道如何使用代码中更改的属性)

我尝试使用多触发器。
            <Button.IsEnabled>
<MultiBinding>
<MultiBinding.Bindings> <Binding ElementName="BlankmeasurementCheckBox" Path="IsChecked"/>
<Binding ElementName="MeasurementCheckBox" Path="IsChecked"/>
</MultiBinding.Bindings>
</MultiBinding>
</Button.IsEnabled>

但这似乎没有帮助。你能帮帮我吗?提前致谢。

最佳答案

您可以使用MultiDataTrigger这里。

这是示例代码:

 <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>

关于wpf - 将按钮的 IsEnabled 属性绑定(bind)到 XAML 中的 2 个复选框 IsChecked 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35862664/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com