如何修改或禁用标题栏中的上下文菜单?
我需要在使用WindowChrome的WPF窗口的标题栏中禁用上下文菜单:
<Window x:Class="WpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
ContextMenu="{x:Null}">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="35"
CornerRadius="0"
ResizeBorderThickness="5"
UseAeroCaptionButtons="False" />
</WindowChrome.WindowChrome>
</Window>
ContextMenu =“{x:Null}”不起作用。 以下说明不起作用:http://codereply.com/answer/7etz8e/remove-title-bars-context-menu-completely-wpf-window.html标题栏中的上下文菜单总是显示为不变。 有人有一个想法?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
IntPtr windowhandle = new WindowInteropHelper(this).Handle;
HwndSource hwndSource = HwndSource.FromHwnd(windowhandle);
hwndSource.AddHook(new HwndSourceHook(WndProc));
}
private const uint WM_SYSTEMMENU = 0xa4;
private const uint WP_SYSTEMMENU = 0x02;
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if ((msg == WM_SYSTEMMENU) && (wParam.ToInt32() == WP_SYSTEMMENU))
{
handled = true;
}
return IntPtr.Zero;
}
}
链接地址: http://www.djcxy.com/p/57393.html
上一篇: How to modify or disable context menu in the title bar?