在WPF中使用MVVM模式在DataGrid中进行文本框验证 [英] TextBox validation inside a DataGrid using MVVM pattern in WPF
本文介绍了在WPF中使用MVVM模式在DataGrid中进行文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在wpf项目中,我有一个DataGrid,其中包含TextBox这样的DataGridTemplate列
In a wpf project i have a DataGrid which contains TextBox as DataGridTemplate column like this
<DataGridTemplateColumn Header="Quantity" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Quantity,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, TargetNullValue=''}" MaxLength="2" IsReadOnly="False"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
推荐答案
您需要创建一个实体类,将表的每一列都保存为属性,该属性由inotifypropertychanged和idataerrorinfo接口继承,然后进行检查.
You need to create a entity class that holds each column of your table as property which is inherited by inotifypropertychanged and idataerrorinfo interface then check out this.
http://www.codegod.de/webappcodegod/wpf-idataerrorinfo-and -databinding-AID416.aspx
谢谢
Rajnikant
Rajnikant
这篇关于在WPF中使用MVVM模式在DataGrid中进行文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文