我正在使用形状绘制地图,然后将其添加到画布,当MouseRightButtonDown时我必须显示ContextMenu,但是当我按下鼠标右键时画布上发生了移动,那么如何停止这种移动?!
private void MainCanvas_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Right)
{
Canvas c = sender as Canvas;
ContextMenu contextMenu = c.ContextMenu;
contextMenu.PlacementTarget = c;
contextMenu.IsOpen = true;
e.Handled = true;
}
}
<Canvas x:Name="MainCanvas" Uid="parentCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MouseDown="MainCanvas_MouseDown">
<Canvas.ContextMenu >
<ContextMenu>
<MenuItem Name="CzechRepublic"
Header="Czech Republic"/>
<MenuItem Name="MiddleEurope"
Header="Middle Europe"/>
<MenuItem Name="Europe"
Header="Europe"/>
<MenuItem Name="WholeMap"
Header="Whole Map"
Click="WholeMap_Clicked"/>
<Separator />
<MenuItem Name="Settings"
Header="Settings"
Click="Settings_Clicked"/>
</ContextMenu>
</Canvas.ContextMenu>