【问题标题】:DataGridCheckBoxColumn immediate bindingDataGridCheckBoxColumn 立即绑定
【发布时间】:2011-02-02 00:00:16
【问题描述】:

我正在使用 WPF Toolkit Datagrid,并且有一列是绑定到我的 ViewModel 上的 bool 属性的 DataGridCheckBoxColumn。

我的问题是,当用户选中或取消选中复选框时,我不希望该属性立即更新其值。

现在您必须离开单元格才能更新属性。这是一个复选框。它不能像文本框那样处于编辑过程中。

【问题讨论】:

    标签: wpf datagrid checkbox


    【解决方案1】:

    您必须将 Binding 的 UpdateSourceTrigger 属性设置为 PropertyChanged。默认为 LostFocus。

    【讨论】:

    • 这也适用于我 (WPF4) - 也许这对于 .NET4 有所改变
    • 对我来说不是。 (WPF4)
    【解决方案2】:

    解决方案是不要为此使用 DataGridCheckBoxColumn。而是使用

    <dg:DataGridTemplateColumn Width="20" Header="" SortMemberPath="IsSelected">
       <dg:DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
             <CheckBox  IsChecked="{Binding Path=IsSelected}" />
           </DataTemplate>
       </dg:DataGridTemplateColumn.CellTemplate>
     </dg:DataGridTemplateColumn>
    

    默认将其 UpdateSourcerigger 设置为 PropertyChanged...

    DataGridCheckBoxColumn 的 UpdateSourceTrigger 设置为 Explicit,并且无法更改。 在这里阅读更多:http://blogs.msdn.com/vinsibal/archive/2009/04/07/5-random-gotchas-with-the-wpf-datagrid.aspx

    【讨论】:

    • 不,它不是默认的。您必须手动设置它,即“UpdateSourceTrigger=PropertyChanged”。否则,您将仅在视觉上进行更改(VS2010)。无论如何,非常感谢您的帮助。
    • 注意:即使是 DataGrid 中的文本框,您也需要执行 UpdateSourceTrigger。在这种情况下可能需要 PropertyChanged=LostFocus(即使这是默认设置)
    • 我在使用 Silverlight 5 时必须这样做
    【解决方案3】:
    猜你喜欢
    • 2018-06-20
    • 2012-05-25
    • 2013-06-15
    • 2022-11-17
    • 2015-05-14
    • 2021-07-08
    • 2011-07-28
    • 2011-05-08
    • 2018-05-23
    相关资源
    最近更新 更多