WPF 工具包:CheckBoxColumn.CheckedChanged 的 DataGrid 事件处理程序?
我目前正在使用 WPF 和包含 WindowsForms 风格的 DataGrid 的 WPF 工具包。
我已将自定义对象列表作为 ItemsSource 绑定到网格。这些对象包含两个布尔属性,可以使用数据网格进行编辑。使用内置数据绑定模型同步回我的列表效果很好,但如果其中一个 CheckBox 值更改为将对象序列化回 XML 中,我必须调用另一种方法。不幸的是,我无法在我的数据类本身中进行此缓存,因为它不知道其缓存提供程序。
因此,我需要 DataGrid 上的一个事件,该事件在复选框值更改后立即触发。
我已经从原始 DataGridCheckBoxColumn 继承了 AutoCommitCheckBoxColumn 类,该类重写了方法 GenerateEditingElement(DataGridCell cell, object dataItem)
以及 checkbox_(Un-)Checked 处理程序。
显然我不能也不想从这里调用缓存方法 - 它需要在 DataGrid 所在的 Window 类中完成。
所以 - 我只是找不到合适的事件: MouseButton.. 事件仅在单击外部单元格空间而不是单元格中的内部复选框时触发。 CellEditEnding 可以工作,但只有在(取消)选中复选框后选择另一个单元格时才会触发。 SourceUpdated 根本不会触发。
有人可以帮我举办试穿活动吗?或者我可以以某种方式从我的 AutoCommitCheckBoxColumn 类安全地触发数据网格上的事件吗?
预先非常感谢您!
I am currently playing around with WPF and the WPF toolkit which contains a WindowsForms-style DataGrid.
I have bound a list of custom objects to the grid as ItemsSource. These objects contain two boolean properties which are editable using the datagrid. Synchronising back into my list works fine using the build-in databinding model but I have to call another method if one of the CheckBox values changed to serialise the object back in XML. Unfortunately I can't do this caching within my data class itself since it doesn't know its cache provider.
Therefore I need an event on the DataGrid which fires right after a checkbox value has changed.
I have already inherited a AutoCommitCheckBoxColumn class from the original DataGridCheckBoxColumn which overrides the method GenerateEditingElement(DataGridCell cell, object dataItem)
and also the checkbox_(Un-)Checked handlers.
Obviously I can't and don't want to call the caching method from here either - it needs to be done in the Window class where the DataGrid resides.
So - I just can't find a proper event for this: The MouseButton.. events only fire when the outer cell space and not the inner checkbox in a cell is clicked. CellEditEnding would work but is only fired if one selects another cell after (un-)checking a checkbox. SourceUpdated doesn't fire at all.
Can anyone help me here with a fitting event? Or can I somehow safely trigger an event on the datagrid from my AutoCommitCheckBoxColumn class?
Thank you very much in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过使用 WPF 数据触发器?
请参阅此处了解更多信息:
http://en.csharp-online.net/WPF_Styles_and_Control_Templates—Data_Triggers
Have you considered using WPF Data triggers?
See here for more info:
http://en.csharp-online.net/WPF_Styles_and_Control_Templates—Data_Triggers