我为列表中的列表项添加了一个点击事件处理程序,下面给出了我的 xaml 代码
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="List" HorizontalAlignment="Left" Height="612" Margin="6,7,0,0" VerticalAlignment="Top" Width="443" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Width="400" Height="50" Tap="StackPanel_Tap_1" >
<TextBlock x:Name="tbName" Width="300" Height="44" FontSize="22" FontWeight="Bold" Text="{Binding Name}" />
<TextBlock x:Name="tbEmail" Width="100" Height="44" FontSize="22" Text="{Binding Amount}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
而我的 C# 代码是,
private void StackPanel_Tap_1(object sender, GestureEventArgs e)
{
NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
}
现在,当我点击列表时,我的导航失败并且函数会自动执行 App.xaml.cs 中的以下内置函数
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
问题是什么?我应该如何纠正它?