假设我有以下数据模板:
<DataTemplate x:Key="ItemTemplate">
<StackPanel>
<Grid Height="95" Width="446" HorizontalAlignment="Left" ShowGridLines="false" RenderTransformOrigin="0.3,0.526">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding categoryimage}" Height="100" Grid.Row="0" Grid.Column="0" />
<TextBlock Text="{Binding categoryname}" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,-46,0" FontSize="26.667"/>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu Name="MyContextMenu">
<toolkit:MenuItem Header="Delete console" Click="contextMenuAction_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Grid>
</StackPanel>
</DataTemplate>
我想在单击上下文菜单项时进行处理。我如何将列表项作为类对象访问(如果这有意义?)
我尝试了以下代码,但是它给了我一个 NullReferenceException 异常:
Private Sub contextMenuAction_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
Dim c As classes.consoles = listBoxview.SelectedItem
MessageBox.Show(c.categoryname)
End Sub