强制进行IDataErrorInfo验证 [英] Force IDataErrorInfo validation
本文介绍了强制进行IDataErrorInfo验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在某些面板上有两个控件:文本框和组合框:
I have two controls on some panel: textbox and combobox:
<TextBox Text="{Binding ShapeName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
<ComboBox SelectedItem="{Binding ActiveStageViewModel, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
当我在组合框上选择某些内容时,我需要强制对文本框进行idataerrorinfo验证.该怎么做?
I need to force idataerrorinfo validation for textbox, when I select something on combobox. How to do that?
viewmodel中的代码:
The code from viewmodel:
string IDataErrorInfo.this[string propertyName]
{
get
{
var error = string.Empty;
if (propertyName == Expression.GetPropertyName(() => ActiveStageViewModel))
{
// TODO: Add functionality to force ShapeName property validation
return error;
}
if (propertyName == Expression.GetPropertyName(() => ShapeName))
{
error = ValidateShapeName();
}
TooltipMessage = error;
return error;
}
}
推荐答案
只需为要验证的属性引发NotifyPropertyChanged
事件,或者如果您使用的是.NET 4.5或Silverlight 4,请使用
Just raise the NotifyPropertyChanged
event for the property you want to validate or if you are in .NET 4.5 or Silverlight 4 use the INotityDataErrorInfo.
这篇关于强制进行IDataErrorInfo验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文