0
我遇到了IDataErrorInfo接口和我正在編程的嚮導的問題。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
}
在調試我可以看到接口被正確handeled。但沒有顯示錯誤。
在XAML綁定設置雙向
<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的文本框,我懷疑此元素的一個錯誤的問題。任何建議都會很棒。
謝謝。
你是如何顯示嚮導的?它是否在窗口內?另外你的屬性是如何定義的(即DependencyProperty或INotifyPropertyChanged)? – Bijington
afaik WPF元素不訂閱IDataErrorInfo,但它們在INotifyDataErrorInfo對象上執行。 – Domysee
所以你應該實現INotifyDataErrorInfo而不是IDataErrorInfo – Domysee