wpf - 如何将对象 bool 属性绑定(bind)到 CheckBox IsChecked 属性?

标签 wpf xaml binding checkbox

我有一个具有 bool 属性的对象的 ObservableCollection。

在 GUI 中,我有一个 CheckBox,我想将其 IsChecked 属性绑定(bind)到每个对象的 bool 属性。

是否可以仅使用 XAML?怎么办?

我只想通过绑定(bind)来做到这一点,因为出价比循环更快

最佳答案

试试这个:

<ListBox ItemsSource={Binding path}>
  <ListBox.ItemTemplate>
    <DataTemplate>
      <CheckBox IsChecked="{Binding yourBoolPropertyName, Mode = TwoWay}" />
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

这将创建将绑定(bind)到您的集合的复选框列表。当然,您必须正确设置绑定(bind)路径。

关于wpf - 如何将对象 bool 属性绑定(bind)到 CheckBox IsChecked 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13590785/

相关文章:

silverlight - 是否有简化 XAML/可视化树(转换 XAML 或 Silverlight 控件实例)的工具?

绑定(bind)和pmap交互变化?

XAML中的WPF MVVM用户控件数据绑定(bind)不起作用

c# - 如何使用异步持续更新 GUI

c# - System.EntryNotFoundException : Unable to find the entry point in the DLL

python - 如何确定按钮何时在 Tkinter 中发布?

c# - 如何在列表框中使用双向绑定(bind)?

wpf - vb.net 中的替换函数

WPF:输入绑定(bind)的命令参数

c# - C#运行时错误: 'Retrieving the COM class factory for component with CLSID failed due to the following error: specified module could not be found