2017-01-09 13 views
1
http://www.mutzl.com/tag/mvvm-light/

MVVM WPF C#の自動プロパティコンボボックス

ノーマルコードこのページに示すように、私は私のコードPropertychanged.Fodyとのビットをリファクタリングしたいと思い

private string _platformSelectedItem; 
     public string PlatformSelectedItem 
     { 
      get { return _platformSelectedItem; } 
      set 
      { 
       if (_platformSelectedItem == value) return; 
       _platformSelectedItem = value; 
       // Perform any pre-notification process here. 
       GetData(); 
       RaisePropertyChanged(); 
      } 
     } 

public string PlatformSelectedItem {get; private set} 

プロパティはComboxboxにバインドされており、Comboboxの値は別のコンボボックスに基づいて動的なので、私は自分のメソッドGetData()を持っています。

<ComboBox ItemsSource="{Binding Platforms}" SelectedItem="{Binding PlatformSelectedItem, Mode=TwoWay}" Grid.Column="1" Grid.Row="2" Height="20" Grid.ColumnSpan="2" Margin="0,3,15.667,3"/> 

私のコードを自動作成機能にリファクタリングする場合、メソッドはコンボボックスのクリック/オープンで実行する必要があります。

私は、コマンドでイベントトリガーを使用する必要がありますか?より簡単な方法は可能ですか?スレッドに基づいて

答えて

0

can we use <i:Interaction.Triggers> in WPF MVVM (not in Silverlight)

私の最終的な解決策にはなります

のViewModelを:

プロパティエリア:

public RelayCommand SelectionChangedCommand { get; private set; } 

コンストラクタ:

SelectionChangedCommand = new RelayCommand(Update); 

メソッドエリア:その後、私のUIで

private void Update() 
    { 
     GetData(); 
    } 

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 

<ComboBox ItemsSource="{Binding Platforms}" SelectedItem="{Binding PlatformSelectedItem, Mode=TwoWay}" Grid.Column="1" Grid.Row="2" Height="20" Grid.ColumnSpan="2" Margin="0,3,15.667,3"> 
         <i:Interaction.Triggers> 
          <i:EventTrigger EventName="SelectionChanged"> 
           <i:InvokeCommandAction Command="{Binding SelectionChangedCommand}"/> 
          </i:EventTrigger> 
         </i:Interaction.Triggers> 
        </ComboBox>