右键单击以显示上下文菜单时如何停止画布移动?

时间:2019-07-04 11:02:17

标签: c# wpf .net-4.0

我正在使用形状绘制地图,然后将其添加到画布,当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>

0 个答案:

没有答案