如何在Silverlight中以编程方式将验证通知文本设置为文本框?

时间:2011-09-14 10:21:31

标签: silverlight validation

我想将验证通知消息设置为文本框控件。我想在TextBox的 BindingValidationError 事件上设置它。

文本框控件的哪个属性将设置验证消息。

I want to set Message like The Name field required

1 个答案:

答案 0 :(得分:0)

在xaml中,

                     Text =“{Binding Path = Name,Mode = TwoWay,NotifyOnValidationError = True,ValidatesOnExceptions = True}”Grid.ColumnSpan =“2”Margin =“97,2,0,2”>

在xaml.cs中,

公共MyViewModel ViewModel         {             得到             {                 return(MyViewModel)this.DataContext;             }             组             {                 this.DataContext = value;             }         }

在 公共类MyViewModel:INotifyPropertyChanged     {

private string _name =“kanal”;         公共字符串名称         {             得到{return _name; }             组             {                 if(string.IsNullOrEmpty(value))                 {                     抛出新的异常(“名称是必需的”);                 }                 _name = value;                 OnPropertyChanged( “名称”);             }         }

protected virtual void OnPropertyChanged(string propertyName)         {             PropertyChangedEventHandler pceh = PropertyChanged;             if(pceh!= null)             {                 pceh(this,new PropertyChangedEventArgs(propertyName));             }         } }