我在viewmodel中进行了数据验证.当我加载视图时,检查验证,而不更改TextBox的内容,这意味着通过加载视图将错误样式设置为TextBox
这是代码:
XAML
<TextBox {...} Text="{Binding Path=ProductName,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"/>
在viewmodel上,使用数据注释进行验证:
码
private string _productName; [required(AllowEmptyStrings = false,ErrorMessage = "The Product Name can't be null or empty.")] [StringLength(50,ErrorMessage = "The Product Name can't be longer than 50.")] [Uniqueness(Entities.Product,ErrorMessage = "A Product with that Name already exists ")] public string ProductName { get { return _productName; } set { _productName = value; SaveProduct.OnCanExecuteChanged(); OnPropertyChanged("ProductName"); } }
视图加载时如何停止验证触发?