如果你只是像我一样把标题中的词汇输入到搜索引擎中,而不是在这里发问,那么你将会找到比这更多的结果。你可以在以下链接中找到答案:
从WPF窗口中删除图标
如何在标题栏中不显示wpf窗口的图标?
如何删除WPF窗口的图标
如何从窗口标题栏中删除图标
如何在WPF中隐藏窗口图标
你最后一条评论让我想起一些问题。于是,我将这段代码添加到了一个大型的应用程序中,并且它依然能够正常工作。然而,我继续测试了一下,你必须在应用程序中使用RibbonWindow
,因为当我在一个带有RibbonWindow
的大型应用程序上测试这段代码时,它就无法正常工作。
如果你正在使用普通的Window
,请尝试使用以下代码(来自于第一个链接帖子中@MichalCiechan的答案):
首先添加以下类:
public static class IconHelper
{
[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x,
int y, int width, int height, uint flags);
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr
lParam);
const int GWL_EXSTYLE = -20;
const int WS_EX_DLGMODALFRAME = 0x0001;
const int SWP_NOSIZE = 0x0001;
const int SWP_NOMOVE = 0x0002;
const int SWP_NOZORDER = 0x0004;
const int SWP_FRAMECHANGED = 0x0020;
const uint WM_SETICON = 0x0080;
public static void RemoveIcon(Window window)
{
// Get this window's handle
IntPtr hwnd = new WindowInteropHelper(window).Handle;
// Change the extended window style to not show a window icon
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);
// Update the window's non-client area to reflect the changes
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
SWP_NOZORDER | SWP_FRAMECHANGED);
}
}
然后将下面的内容添加到MainWindow.xaml.cs
中:
protected override void OnSourceInitialized(EventArgs e)
{
IconHelper.RemoveIcon(this);
}
哦……还有一件事要注意……如果您设置了 Window.Icon
属性,它将无法正常工作,但我猜您没有这样做,因为您不想显示图标。