禁用Win窗口的ContextMenu菜单 – 三郎君的日常

面试 · 2024年10月22日

禁用Win窗口的ContextMenu菜单

  1. 自定义窗口边框

鼠标右键点击便不会弹出

2.将ContextMenu菜单和右键点击方法重写

MouseRightButtonDown="Window_MouseRightButtonDown"
        IsWindowDraggable="False">
    <Window.ContextMenu>
        <ContextMenu x:Name="EmptyContextMenu">
        </ContextMenu>
    </Window.ContextMenu>
private void Window_MouseRightButtonDown(object sender, MouseButtonEventArgs e) {
            if (this.EmptyContextMenu != null) {
                this.EmptyContextMenu.IsOpen = true;
            }
            // 阻止系统右键菜单
            e.Handled = true;
        }