私はMVVMLightを使用しています。標準ビューとビューモデルを作成しました。ビューでは、ピボットを配置しました:
<Grid x:Name="LayoutRoot" Background="Transparent">
<controls:Pivot Title="MY APPLICATION">
<local:FirstPivotItem />
<local:SecondPivotItem />
</controls:Pivot>
</Grid>
ここで、私のピボット アイテムは次のようになります。
<controls:PivotItem x:Class="Pivot.WindowsPhoneControl1"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
// standard references and settings
d:DesignHeight="480" d:DesignWidth="480" Header="First One">
<Grid x:Name="LayoutRoot">
</Grid>
</controls:PivotItem>
コード ビハインドで
public partial class WindowsPhoneControl1 : PivotItem
{
public WindowsPhoneControl1() {
InitializeComponent();
}
}
このピボット アイテムのビューモデルを作成し、標準ビューと同じように操作したいと考えています。私が使用します
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<mvvm:EventToCommand Command="{Binding PivotChangedCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
選択変更イベントを処理し、メッセンジャーによって適切なビューモデルに通知します。必要に応じて、ViewModelBase からではなく PivotItem から継承された Pivot Item クラスでビューモデルの可能性を使用する方法がわかりません。