首先要加上两个命名空间
分别为:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
然后
<Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="170,239,0,0" Grid.Row="1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ec:NavigateToPageAction TargetPage="/Page1.xaml"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
使用NavigateToPageAction还可以传递查询字符串:
我们可以用NavigationContext.QueryString,把查询字符串读出来
//NavigateToPageAction is also very useful for Binding data to NavigationContext.QueryString
<ListBox>
...
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<ec:NavigateToPageAction>
<ec:NavigateToPageAction.TargetPage>
<Binding Path="SelectedIndex" ElementName="MainListBox"
StringFormat="/DetailsPage.xaml?selectedItem={0}"/>
</ec:NavigateToPageAction.TargetPage>
</ec:NavigateToPageAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>