进入空间时文本框奇怪的行为

时间:2012-11-29 20:59:02

标签: c# validation textbox silverlight-5.0 inotifydataerrorinfo

我正在使用Silverlight 5和C#。我的模型(CustomerModel)实现了INotifyDataErrorInfo接口来验证用户输入。其Text属性绑定到模型中的Property的TextBox在每次击键时都被验证(我已设置UpdateSourceTrigge=PropertyChanged),表现得很奇怪 - 当我输入空格时,光标移动到开头TextBox的。{非常烦人。

<TextBox x:Name="txtDebtorName" Grid.Row="2" Grid.Column="1"
           Text="{Binding SelectedItem.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
           IsReadOnly="{Binding IsReadonly}" >
</TextBox>

任何想法是什么导致了这种行为,以及如何解决它?

模型中的属性:

public string Name
{
    get { return _Name; }
    set
    {
        const string propertyName = "Name";
        ValidateRequiredString(propertyName, value, Utility.GetTranslation("RequiredFieldDebtorName"));

        _Name = value;
        RaisePropertyChanged(propertyName);
    }
}

ValidateRequiredString()方法采用PropertyName,设置的值和错误消息。

0 个答案:

没有答案
相关问题