嗨,这是使用 xaml 页面,我想使用选定的项目导航。
<ListBox x:Name="NotchsList11" Margin="0,0,0,0" Grid.Row="3" HorizontalAlignment="left" Width="Auto" Grid.RowSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Top" Width="Auto">
<ListBox ItemsSource="{Binding Images}" Width="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionChanged="NotchsList11_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Width="152" Height="90" Stretch="Fill" VerticalAlignment="Top">
</Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的 xaml.cs 页面代码如下
private void NotchsList11_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Notch selectedItemData = (sender as ListBox).SelectedItem as Notch;
if(selectedItemData != null)
{
NavigationService.Navigate(new Uri(string.Format("/Test.xaml?parameter={0}",selectedItemData.articleid), UriKind.Relative));
}
}
如果我选择任何一项我无法导航到其他页面,因为我收到错误 selectedItemData is null.so 任何人都可以帮助我吗?