我遇到了IDataErrorInfo接口和我当前正在编程的向导的问题。
我的程序的目的是询问一些输入(通常是用条形码扫描仪完成的),并根据输入启动特定的序列。这是像intendet一样工作的。为了确保捕获到错误的扫描,所有输入都会通过一个事件( 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,但由于textbox类是基于wpf textbox的,所以我怀疑这个元素中的错误是不是问题所在。任何建议都是很棒的。
谢谢。
发布于 2015-12-01 18:27:34
Domysee的回答帮助了我。
实现INotifyDataErrorInfo而不是IDataErrorInfo是一个重大的变化,但它解决了这个问题!
https://stackoverflow.com/questions/33996537
复制相似问题