嗨,这是我使用xaml页面,我想用选定的项目导航。下面如何设置将页面传递到另一个页面的值?
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));
}
}
<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页面代码中给出,如果我选择任何一个项目,我不能浏览其他页面,因为我得到了错误selectedItemData是null.so任何一个可以帮助我?
什么是列表框的类的ItemSource? selectedItemData为null是因为投射到Notch可能不起作用。 – 2013-03-26 22:16:31
在函数的第一行放置一个断点,然后在立即窗口中输入“(sender as ListBox).SelectedItem”而不带引号。如果它不为空,那么你可以看到什么样的项目。 – 2013-03-26 22:52:03