-1

データのリストがあります。各行にはデータが表示され、ボタンがあります。表示されているデータをクリックすると、前のページにデータが表示され、同じ行のボタンをクリックすると送信されます次のページに同じデータ。

私の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の、null 例外を取得し、

An exception of type 'System.NullReferenceException' occurred in ExpenseApp.DLL but was not handled in user code

機能させるにはどうすればよいですか?

4

2 に答える 2