0

我有一个实现 INotifyDataErrorInfo 的 ViewModel,以及一个绑定到该 ViewModel 的 View。

ViewModel 包含一个 Double 类型的属性,在 View 中包含一个 TextBox,其 Text 属性绑定到该 Double 属性。

public double Value
{
    get { return _value; }
    set
    {
        _value = value;
        NotifyPropertyChangedAndValidate();
    }
}
<TextBox Text="{Binding Path=Value, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />

在 viewModel 的索引器中(来自 INotifyDataErrorInfo),我可以验证插入的值,例如检查它是否不超过某个边界。这样的错误消息然后我可以通过<ItemsControl ItemsSource="{Binding Path=Errors}" ItemTemplate="{StaticResource ResourceKey=WrapTemplate}" />

但是,当将无效字符插入文本框时,索引器(或整个 INotifyDataErrorInfo 实现)不会获得该值,因此他无法生成适合该错误插入的错误消息。当插入无效字符时,如何实现来自索引器的错误消息可以以与 .NET 内部生成的相同行为显示在屏幕上?

4

0 回答 0