更改 WPF 标题栏背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1283006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing WPF title bar background color
提问by Emad Gabriel
I have a WPF Windows application. I need to change the background color of the title bar. How can I do that?
我有一个 WPF Windows 应用程序。我需要更改标题栏的背景颜色。我怎样才能做到这一点?
采纳答案by Marcel B
In WPF the titlebar is part of the non-client area, which can't be modified through the WPF window class. You need to manipulate the Win32 handles (if I remember correctly).
This article could be helpful for you: Custom Window Chrome in WPF.
在 WPF 中,标题栏是非客户区的一部分,不能通过 WPF 窗口类进行修改。您需要操作 Win32 句柄(如果我没记错的话)。
本文可能对您有所帮助:WPF 中的自定义窗口 Chrome。
回答by Sushant Khurana
Here's an example on how to achieve this:
这是有关如何实现此目标的示例:
<Grid DockPanel.Dock="Right"
HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right"
VerticalAlignment="Center">
<Button x:Name="MinimizeButton"
KeyboardNavigation.IsTabStop="False"
Click="MinimizeWindow"
Style="{StaticResource MinimizeButton}"
Template="{StaticResource MinimizeButtonControlTemplate}" />
<Button x:Name="MaximizeButton"
KeyboardNavigation.IsTabStop="False"
Click="MaximizeClick"
Style="{DynamicResource MaximizeButton}"
Template="{DynamicResource MaximizeButtonControlTemplate}" />
<Button x:Name="CloseButton"
KeyboardNavigation.IsTabStop="False"
Command="{Binding ApplicationCommands.Close}"
Style="{DynamicResource CloseButton}"
Template="{DynamicResource CloseButtonControlTemplate}"/>
</StackPanel>
</Grid>
</DockPanel>
Handle Click Events in the code-behind.
在代码隐藏中处理单击事件。
For MouseDown -
对于鼠标按下 -
App.Current.MainWindow.DragMove();
For Minimize Button -
对于最小化按钮 -
App.Current.MainWindow.WindowState = WindowState.Minimized;
For DoubleClick and MaximizeClick
对于 DoubleClick 和 MaximizeClick
if (App.Current.MainWindow.WindowState == WindowState.Maximized)
{
App.Current.MainWindow.WindowState = WindowState.Normal;
}
else if (App.Current.MainWindow.WindowState == WindowState.Normal)
{
App.Current.MainWindow.WindowState = WindowState.Maximized;
}
I hope this helps.
我希望这有帮助。
回答by Thomas Levesque
You can also create a borderless window, and make the borders and title bar yourself
也可以创建无边框窗口,自己制作边框和标题栏
回答by Abou-Emish
Check the following sample WPF customizing the appearance of a window in XAML
检查以下示例WPF 在 XAML 中自定义窗口的外观
This sample shows how to fully customize the style/appearance of a window, including the non-client areas: title bar, borders, max, min and close buttons whilst still providing all the expected functionality.
此示例展示了如何完全自定义窗口的样式/外观,包括非客户区域:标题栏、边框、最大、最小和关闭按钮,同时仍提供所有预期功能。