2011-01-23 5 views
2

私はMVVMを使用してプロパティにバインドされたcomboxコントロールを持っています。値変更のセット方法で行う検証が...問題は値が検証に失敗した場合でも、新しい値に変更して、以前の値を保持しませばかり..ですがあります以下WPF MVVM Comboxは検証で古い値を保持できません

はXAMLです:

以下は
<ComboBox Grid.Column="1" Grid.Row="1" Width="200" ItemsSource="{Binding Path=Applications, Mode=OneTime}" SelectedItem="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.Application, Mode=TwoWay}" Margin="3"></ComboBox> 

ビューモデルコードです:あなたはプロパティのセッターで最後の行でOnPropertyChangedを(...)を欠けているよう

private string[] types = new string[] { "A", "B" }; 

private string application; 

public ObservableCollection<string> Applications { get; private set; } 

public Const() { 
     this.Applications = new ObservableCollection<string>(this.types.ToList()); 
    } 

public string Application { 
     get { 
      this.application = this.applicationSpecificRequirements.ContainsKey(Resources.ApplicationKey) ? this.applicationSpecificRequirements[Resources.ApplicationKey] : this.Applications[0]; 
      return this.application; 
     } 

     set { 
      if (this.exchangeViewModel.CheckIfApplicationNameExistsOrIsEmptyAndAssign(this.InstanceName, value)) { 
       System.Windows.Application.Current.Dispatcher.BeginInvoke(
        new Action(() => { 
         this.applicationSpecificRequirements[Resources.ApplicationKey] = this.application; 
         ((IHaveOnPropertyChangedMethod) this).OnPropertyChanged("Application"); 
        }), DispatcherPriority.ContextIdle, null); 

       return; 
      } 

      this.applicationSpecificRequirements[Resources.ApplicationKey] = value; 
     } 
    } 

答えて

0

が見えます。

+0

dintが動作しようとしましたが、検証が失敗した場合、if文の中に入り、値を設定してしまうという問題があります。しかし、同じことがUIに反映されていません..検証がない場合は同じ作品が、その後、値がchnaged ..取得私は古い値を保持する必要があります – Arihant

関連する問題