【问题标题】:How to set validation notification text programatically to textbox in silverlight?如何以编程方式将验证通知文本设置为 Silverlight 中的文本框?
【发布时间】:2011-09-14 10:21:30
【问题描述】:

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

文本框控件的什么属性会设置验证消息。

I want to set Message like The Name field required

【问题讨论】:

    标签: silverlight validation


    【解决方案1】:

    在 xaml 中,

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

    在 xaml.cs 中,

    公共 MyViewModel ViewModel { 得到 { 返回(MyViewModel)this.DataContext; } 放 { this.DataContext = 值; } }

    在 公共类 MyViewModel:INotifyPropertyChanged {

    私有字符串 _name = "kanal"; 公共字符串名称 { 得到 { 返回 _name; } 放 { 如果(字符串.IsNullOrEmpty(值)) { throw new Exception("名称为必填项"); } _name = 值; OnPropertyChanged("名称"); } }

    受保护的虚拟 void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler pceh = PropertyChanged; 如果(pceh!= null) { pceh(this, new PropertyChangedEventArgs(propertyName)); } } }

    【讨论】:

    • Thomas 我不想通过 MVVM 来做。我想要后面的代码
    猜你喜欢
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 2018-11-25
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多