wpf 在 Window 的标题栏中/上方添加 UserControl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18940919/
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
Add a UserControl in/over titlebar in Window
提问by SubmarineX
In WPF, I want to add a userControl in/over titlebar in Window, like this:
在 WPF 中,我想在 Window 的标题栏中/上方添加一个 userControl,如下所示:


The Red part is that UserControl, and the Green part is titlebar.
红色部分是UserControl,绿色部分是标题栏。
Now I hope to get some suggestions from you. Need to extend the Window class or just customize the style of the Window? It's better to provide source code.
现在我希望得到你的一些建议。需要扩展 Window 类还是只自定义 Window 的样式?最好提供源代码。
回答by Omri Btian
You can do this by implementing your own title bar. In order to do so set your window style to none:
您可以通过实现自己的标题栏来做到这一点。为此,请将您的窗口样式设置为无:
WindowStyle="None"
This will mean that the window will have no control box (minimize, maximize, and close buttons) and you will need to implement your own.
这意味着该窗口将没有控制框(最小化、最大化和关闭按钮),您需要实现自己的控制框。
You can take a look at the following links to get you started:
您可以查看以下链接以开始使用:
http://blog.magnusmontin.net/2013/03/16/how-to-create-a-custom-window-in-wpf/
http://blog.magnusmontin.net/2013/03/16/how-to-create-a-custom-window-in-wpf/
http://www.codeproject.com/Articles/140267/Create-Custom-Windows-in-WPF-with-Ease
http://www.codeproject.com/Articles/140267/Create-Custom-Windows-in-WPF-with-Ease
http://www.kirupa.com/blend_wpf/custom_wpf_windows.htm
http://www.kirupa.com/blend_wpf/custom_wpf_windows.htm
How can I style the border and title bar of a window in WPF?
Good luck
祝你好运
回答by meilke
You do not need to sub-class Window. You can adjust the style for Window: http://msdn.microsoft.com/en-us/library/aa969824.aspx.
你不需要子类Window。您可以调整样式Window:http: //msdn.microsoft.com/en-us/library/aa969824.aspx。
回答by PostureOfLearning
Using a UI toolkit such as Mahapp, your development time will be significantly less.
使用诸如 Mahapp 之类的 UI 工具包,您的开发时间将显着减少。

