I have created a WPF Window and set its Window Style property to 'None'.
Yet when I press Alt+Up Key combination, a context menu appears on the top left of the Window.
有没有办法也禁用它..
注意:处理 PreviewKeyDown 事件可以完成这项工作,但我正在寻找不同的方法。
<Window
x:Class="WpfApplication14.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
Title="MainWindow" Height="350" Width="525">
<Grid/>
</Window>
在代码后面添加以下代码将清除标题栏的样式并阻止系统菜单:
private const int GWL_STYLE = -16; //WPF's Message code for Title Bar's Style
private const int WS_SYSMENU = 0x80000; //WPF's Message code for System Menu
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
// Handling the Messages in Window's Loaded event
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
}
取自 :如何在WPF窗口中隐藏关闭按钮? https://stackoverflow.com/questions/743906/how-to-hide-close-button-in-wpf-window/958980#958980
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)