【发布时间】:2011-11-10 15:33:16
【问题描述】:
正如标题所示,我有一个带有上下文菜单的列表框。我正在尝试通过上下文菜单从列表框中的条目中获取值。我目前拥有的代码如下;
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="#90361F" BorderThickness="3" CornerRadius="5" Margin="5">
<StackPanel Orientation="Vertical" Background="#90361F" Width="488">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu Tag="{Binding .}">
<toolkit:MenuItem Click="MenuItemDelete_Click" Header="Delete Timer"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<StackPanel Orientation="Vertical" Background="#90361F" Width="488" >
<TextBlock Text="{Binding e2name}" Foreground="White" FontSize="25"/>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="{Binding name}" Foreground="White" FontSize="15" Tag="{Binding name}"/>
<TextBlock Text="{Binding datetime}" Foreground="White" FontSize="15" HorizontalAlignment="Right"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
现在是上下文菜单点击事件
private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
{
var me = ((FrameworkElement)sender).Tag as ListBoxItem;
}
我正在尝试从名称绑定中获取值,我也在使用标签来尝试传递数据。正如您从我的点击事件中看到的那样,这很垃圾!根据我的阅读和理解,我确实需要使用 ((FrameworkElement)sender).Tag 但我不确定如何初始化它。 谢谢
【问题讨论】:
标签: c# xaml windows-phone-7