1
我得到我要離開的Pivot項目的索引,而不是我要去的Pivot項目。
我已經搜索了一段時間,可以想到一些解決方案,比如在視圖中使用事件,然後使用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);
}
謝謝!我已經嘗試綁定SelectedItem屬性,但我不知道TwoWay綁定模式。現在一切正常!謝謝 – Raymen 2012-01-10 20:18:09
@RaymenScholten使用拖曳方式綁定,您可以選擇ViewModel中的項目以顯示在視圖中和副本中。它在這個senario非常方便.. – Ankesh 2012-01-10 20:20:13