System.NullReferenceException Windows Phone 8.1

时间:2016-01-23 10:47:31

标签: windows-phone-8.1

我想删除所选的堆栈面板,但是当我选择堆栈面板时,它会提供异常

            <ListBox x:Name="listbox1" Background="{x:Null}"        
                     Margin="-2,51,-4,647" BorderBrush="{x:Null}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Tag="{Binding Weight_ID}"  
                                   Tapped="StackPanel_Tapped"  >

                         <StackPanel Orientation="Horizontal">
                                <TextBlock x:Name="date" Text=" Date">                      
                                </TextBlock>
                                <TextBlock Text="{Binding Date_}" >
                         </StackPanel>    
                         </StackPanel>
                         </DataTemplate>
                         </ListBox.ItemTemplate>
                         </ListBox>


    private void StackPanel_Tapped(object sender, TappedRoutedEventArgs e)
    {

       string id = (((e.OriginalSource) as TextBlock).Tag).ToString();
    }

1 个答案:

答案 0 :(得分:0)

不使用Stackpanel上的Tapped事件处理程序,而是在listView上使用ItemClick事件处理程序并输入您想要的内容