gpt4 book ai didi

wpf - 如何在同一个复选框命令中使用 isChecked 作为命令参数

转载 作者:行者123 更新时间:2023-12-03 10:11:44 25 4
gpt4 key购买 nike

所以我有一个复选框,它使用 WPF/MVVM 触发命令,这工作正常,但我想使用复选框的 IsChecked 属性作为命令参数。我试过这个。

  <CheckBox Margin="3" Content="Clear Selected OEM" 
Command="{Binding Path=ClearOemCommand}"
CommandParameter="{Binding Path=IsChecked}"/>

但是我在输出窗口中收到一个错误,上面写着
System.Windows.Data Error: 40 : BindingExpression path error: 'IsChecked' property not found on 'object'

如果我想使用另一个控件的属性,我会知道如何使用 find 祖先,但我在这里被难住了 - 这可能比我想象的要容易......只是没有在我的脑海中建立联系。

谢谢!

最佳答案

请在 CommandParameter 中添加 RelativeSource Self

  <CheckBox Margin="3" Content="Clear Selected OEM" 
Command="{Binding Path=ClearOemCommand}"
CommandParameter="{Binding Path=IsChecked, RelativeSource={RelativeSource Self}}" />

关于wpf - 如何在同一个复选框命令中使用 isChecked 作为命令参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5650143/

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