永远不会调用 C# WPF IDataErrorInfo 索引器

C# WPF IDataErrorInfo indexer is never called

我正在尝试使用 IDataErrorInfo 实现简单验证并遇到问题 - IDataErrorInfo 索引器从未被调用。我正在为具有指定范围的数值验证 TextBox,类型验证工作正常但范围验证不起作用。 C#代码:

public interface IDataErrorInfo
{
    string Error { get; }
    string this[string columnName] { get; }
}

public class Bounds:IDataErrorInfo
{
    int lbw = 0;

    public int LBW
    {
        get { return lbw; }
        set { lbw = value; }
    }


    public string this[string columnname]
    {
        get
        {
            string error = String.Empty;
            switch(columnname)
            {
                case "LBW":
                    if (0 >= lbw || 500 < lbw)
                    {
                        error = "out of range";
                    }
                    break;
            }
            return error;
        }
    }
    public string Error
    {
        get { return null; }
    }
}

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        Bounds bounds = new Bounds(rolletBoundLbwBox);
        rolletBoundGrid.DataContext = bounds;

    }
}

xaml代码:

<Grid x:Name="rolletBoundGrid" Background="#FFE5E5E5">
        <TextBox x:Name="rolletBoundLbwBox" HorizontalAlignment="Left" Height="26" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="164,10,0,0"  Text="{Binding LBW, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"/>
 </Grid>

你明白问题的原因了吗?

您是否正在实施内置System.ComponentModel.IDataErrorInfo接口?

public class Bounds: System.ComponentModel.IDataErrorInfo
...

如果您实现自己的自定义界面恰好命名为 "IDataErrorInfo"。

则不起作用