2012-01-10 3 views
1

私が行っているピボットアイテムのインデックスを取得します。
私はしばらくの間検索しましたが、ビュー内のイベントを使用し、MVVM-Lightを使用してViewModelにメッセージを送信するようないくつかのソリューションを考えることができます。しかし、私はむしろそれをやりたいのですが、私はむしろこの現在の実装に固執したいと思います。ピボットコントロールMVVM-Light-EventToCommand SelectedIndexが前のインデックスを送信

すべてのヘルプは

私のXAMLを高く評価されています

<controls:Pivot x:Name="ContentPivot" Margin="12,0,12,0"> 
     <i:Interaction.Triggers> 
      <i:EventTrigger EventName="SelectionChanged"> 
       <cmd:EventToCommand Command ="{Binding SelectSlideCommand}" 
             CommandParameter="{Binding SelectedIndex, ElementName=ContentPivot}" /> 
      </i:EventTrigger> 
     </i:Interaction.Triggers> 

     <controls:PivotItem x:Name="PivotItem0" Header="0"> 
      <Image Source="{Binding ViewingSlides[0].Path}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
     </controls:PivotItem> 

     <controls:PivotItem x:Name="PivotItem1" Header="1"> 
      <Image Source="{Binding ViewingSlides[1].Path}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
     </controls:PivotItem> 

     <controls:PivotItem x:Name="PivotItem2" Header="2"> 
      <Image Source="{Binding ViewingSlides[2].Path}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
     </controls:PivotItem> 
    </controls:Pivot> 

とC#:

public RelayCommand<int> SelectSlideCommand; 

    SelectSlideCommand = new RelayCommand<int>((pivotItem) => SelectSlideAction(pivotItem)); 

    void SelectSlideAction(int parameter) 
    { 
     currentIndex = parameter; 

     UpdateViewingSlides(); 
     Debug.WriteLine("SelectSlideAction: " + parameter); 
    } 

答えて

2

あなたがコントロールで `のSelectedItemプロパティを持っていますか...あなたはそれをフックすることができますあなたのViewModelをTwoWayバインディングモードのプロパティに変更して、常に更新された値を取得します(このコマンドは必要ありません)。また、試してみることもできます。

 <i:Interaction.Triggers> 
     <i:EventTrigger EventName="SelectionChanged"> 
      <cmd:EventToCommand Command ="{Binding SelectSlideCommand}" 
            CommandParameter="{Binding SelectedItem, ElementName=ContentPivot}" /> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 
+0

ありがとう!私はすでにSelectedItemプロパティをバインドしようとしましたが、TwoWayバインディングモードについてはわかりませんでした。それはすべて今働く!ありがとうございました – Raymen

+0

@RaymenScholtenトウイングバインディングを使用すると、ViewModelから表示するアイテムと逆のアイテムを選択できます。その非常に便利なこのシナリオでは.. – Ankesh

関連する問題