我有一个数据列表,每行将显示一个数据并有一个按钮,当我单击显示的数据时,我想将一些数据提供给上一页,当我单击同一行中的按钮时,我想发送该数据相同的数据到下一页。
我的 Xaml 代码,
<ListBox x:Name="List" HorizontalAlignment="Left" Height="612" Margin="6,7,0,0" VerticalAlignment="Top" Width="443" SelectionChanged="List_SelectionChanged_1">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Width="420" Height="50">
<TextBlock x:Name="tbName" Width="400" Height="44" FontSize="22" FontWeight="Bold" Text="{Binding Name}" />
<Button x:Name="DetailButton" Height="44" Width="20" Content=">" FontWeight="Bold" Click="DetailButton_Click_1"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
List_SelectionChanged_1事件处理程序的代码是,
private void List_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
Display selectedItemData = (sender as ListBox).SelectedValue as Display;
NavigationService.Navigate("/Page1.xaml",selectedItemData);
}
我的DetailButton_Click_1事件处理程序是,
private void DetailButton_Click_1(object sender, RoutedEventArgs e)
{
Display selectedItemData = (sender as ListBox).SelectedValue as Display;
NavigationService.Navigate("/page3.xaml", selectedItemData);
}
*List_SelectionChanged_1* 工作正常,但执行时出现异常
Display selectedItemData = (sender as ListBox).SelectedValue as Display;
的DetailButton_Click_1,我得到一个异常空异常,
An exception of type 'System.NullReferenceException' occurred in ExpenseApp.DLL but was not handled in user code
我应该怎么做才能让它工作?