WPF DataGrid在单元格更改上立即更新 [英] WPF DataGrid immediate update on Cell Change
本文介绍了WPF DataGrid在单元格更改上立即更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让ViewModel在单元格的值更改时立即更新.现在必须等到焦点离开记录.
I would like to have the ViewModel updated immediately on change of value of a cell. Right now have to wait until focus leaves the record. Is there a XAML attribute I can set to cause immediate update?
推荐答案
尝试将Binding的UpdateSourceTrigger属性设置为PropertyChanged.默认值为LostFocus.
Try to set the UpdateSourceTrigger property of the Binding to PropertyChanged. The default is LostFocus.
<object UpdateSourceTrigger="UpdateSourceTrigger" .../>
请参考msdn以获取更多信息:
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger.aspx [ ^ ]
Please refer to msdn for further info:
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger.aspx[^]
了解此问题的最佳位置是http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c71fe21a-6549 -4dcf-aee9-43d02e73194f [ ^ ].这是我的解决方案中的一些代码:
The best place to see about this problem is http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c71fe21a-6549-4dcf-aee9-43d02e73194f[^]. Here is some of the code from my solution:
<datagrid>
<datagrid.resources>
<style x:key="TextBlockRightAlignStyle" xmlns:x="#unknown">
TargetType="{x:Type TextBlock}">
<setter property="TextAlignment">
Value="Right" />
<setter property="Padding">
Value="5,0" />
<setter property="VerticalAlignment">
Value="Center" />
</setter></setter></setter></style>
<style x:key="TextBoxRightAlignStyle" xmlns:x="#unknown">
TargetType="{x:Type TextBox}">
<setter property="TextAlignment">
Value="Right" />
<setter property="Background">
Value="Transparent" />
<setter property="Padding">
Value="5,0" />
<setter property="VerticalAlignment">
Value="Center" />
</setter></setter></setter></setter></style>
</datagrid.resources>
<datagrid.columns>
<datagridtextcolumn header="Amount">
Binding="{Binding Amount, StringFormat={}{0:#\,###},
UpdateSourceTrigger=LostFocus}"
ElementStyle="{StaticResource TextBlockRightAlignStyle}"
EditingElementStyle="{StaticResource TextBoxRightAlignStyle}"
Width="130" />
</datagridtextcolumn></datagrid.columns>
</datagrid>
我包含了对齐内容,因为有人可能会觉得有用.
I included the alignment stuff since somebody may find it useful.
这可以100%
http://social.msdn.microsoft.com/Forums/en/wpf/thread/a814c74f-6fa0-48f7-a790-8e753da422a8
This works 100%
http://social.msdn.microsoft.com/Forums/en/wpf/thread/a814c74f-6fa0-48f7-a790-8e753da422a8
这篇关于WPF DataGrid在单元格更改上立即更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文