How to modify or disable context menu in the title bar?
I need to disable context menu in the title bar in the WPF window which uses WindowChrome:
<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}" doesn't work. The following instructions don't work too: http://codereply.com/answer/7etz8e/remove-title-bars-context-menu-completely-wpf-window.html The context menu in the title bar appears always with no change. Somebody has an idea?
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/57394.html
上一篇: 在Avalandock中禁用“Dock作为选项卡式文档”
下一篇: 如何修改或禁用标题栏中的上下文菜单?