如果我点击图钉,上下文菜单将打开并显示详细信息。现在我想点击/单击上下文菜单来执行一些事件。如何实现这一点???谢谢
<Style x:Key="MenuItemStyle" TargetType="toolkit:MenuItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="toolkit:MenuItem">
<StackPanel>
<TextBlock Text="{Binding Name}"
TextWrapping="Wrap"
Margin="24,0"
FontSize="26" Foreground="Black"/>
<TextBlock Text="{Binding Country}"
Margin="24,0"
FontSize="22" Foreground="Black"/>
<TextBlock Text="{Binding Status}"
Margin="24,0"
FontSize="22" Foreground="Black"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
private void Pushpin_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
var _ppmodel = sender as Pushpin;
ContextMenu contextMenu =
ContextMenuService.GetContextMenu(_ppmodel);
contextMenu.DataContext = _viewModel.Pushpins.Where
(c => (c.Coordinates
== _ppmodel.Location)).FirstOrDefault();
if (contextMenu.Parent == null)
{
contextMenu.IsOpen = true;
}
}
要处理对上下文菜单项的点击/单击,您必须添加适当的事件。
例如
<Style x:Key="MenuItemStyle" TargetType="toolkit:MenuItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="toolkit:MenuItem">
<StackPanel Tap="OnMenuItemTapped">
...
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter
</Style>