我在某些面板上有两个控件:文本框和组合框:
<TextBox Text="{Binding ShapeName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
<ComboBox SelectedItem="{Binding ActiveStageViewModel, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
当我在组合框上选择某些内容时,我需要强制对文本框进行idataerrorinfo验证。怎么做?
来自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中,请使用INotityDataErrorInfo。
关于wpf - 强制进行IDataErrorInfo验证,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13378474/