IDataErrorInfo未更新

时间:2015-11-30 10:35:13

标签: c# wpf

我遇到了IDataErrorInfo接口和我正在编程的向导的问题。

我的程序的目的是询问一些输入(通常使用条形码扫描仪)并根据输入启动特定序列。 这是有意义的。为了确保捕获错误的扫描,所有输入都会检查事件(OnValueParseFailed)如果触发此事件,我的当前文本框将被聚焦并选择所有文本:

    this.MyWizardViewModel.ValueParseFailed += (s, e) =>
    {
        switch (e.Parameter)
        {
            case "ProductionOrder":                            
                this.TextBoxProduction.Focus();
                this.TextBoxProduction.SelectAll();
                break;

接口本身就是这样包含的:

    public string this[string name]
    {
        get
        {
            string result = null;

            if ((name == "ProductionOrder") && (!string.IsNullOrEmpty(this.ProductionOrder)))
            {
                if (this.System.FirmwareVersion == 0)
                    result = Lang.Strings.WrongEntry;
            }

它的第一次运行。但是,如果向导已完成或中止并在不关闭应用程序的情况下再次运行,则不会显示任何错误消息。

重置只会将应用程序返回默认值。

    public void ResetApplikation()
    {
        this.System.Clear();  // reset System values

        this.ProductionOrder = string.Empty;
        this.BmsTypeCode = string.Empty;
        this.CellStack1TypeCode = string.Empty;
        this.CellClass1 = string.Empty;
        this.CellStack2TypeCode = string.Empty;
        this.CellClass2 = string.Empty;
        this.IsSystemProgrammed = false;
        this.IsSystemParameterized = false;

        this.MyMachine.Abort();  // reset wizard state
    }

调试时我可以看到接口正确处理。但是没有显示错误。

在XAML中,绑定设置为TwoWay

    <TextBox Name="TextBoxProduction" Grid.Row="2" Width="200"  Margin="10"
     Style="{StaticResource TextBoxNormal}" Loaded="TextBoxProduction_Loaded"
     Text="{Binding Path=ProductionOrder, ValidatesOnDataErrors=True,   
     NotifyOnValidationError=True, Delay=100,    
     UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

我正在使用MahApps,但由于文本框类基于wpf文本框,我怀疑这个元素中的错误是问题所在。任何建议都会很棒 谢谢。

1 个答案:

答案 0 :(得分:0)

Domysee的回答帮助了我。

实现INotifyDataErrorInfo而不是IDataErrorInfo是一个重大变化,但它解决了这个问题!

相关问题