如果您只是将标题中的单词放入搜索引擎,而不是像我刚才所做的那样,那么您会发现比这些更多的结果。你可以在下面找到你的答案:
Removing Icon from a WPF window
Is it possible to display a wpf window without an icon in the title bar?
How to remove the icon of a WPF window
How to remove Icon from window titlebar
How to hide window icon in 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 属性,它将不起作用,但我猜如果您不想要图标。