如何使用 WPF 创建看起来像 Windows 7 中的通知区域窗口的窗口?
有没有办法使用 Windows Presentation Foundation 创建像本机 Windows 7 通知区域 Windows 一样的窗口?例如音频控件或电源计划设置。
我能够使用 Windows 窗体创建一个看起来相同的窗口,但当您将鼠标悬停在边框上时仍然具有调整大小光标。我使用以下代码:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="NoResize" ShowInTaskbar="False" Topmost="True"
DataContext="{Binding}" WindowStyle="SingleBorderWindow"
WindowStartupLocation="Manual" ShowActivated="False"
IsManipulationEnabled="False" mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="218" d:DesignWidth="368" SizeToContent="WidthAndHeight">
<Grid>
</Grid>
</Window>
我的问题是我无法完全删除标题栏和关闭按钮。或者是否有可用于创建此类窗口的库?
我想发布截图,但我无法发布,因为我还没有 10 点声望点。
感谢您的帮助!
Is there a way to create windows like the native Windows 7 notification area Windows with Windows Presentation Foundation? For example the audio controls or the power plan settings.
I was able to create a Window with Windows Forms that was looking equal, but still had the resize cursor when you hovered the borders. I’m using the following code:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="NoResize" ShowInTaskbar="False" Topmost="True"
DataContext="{Binding}" WindowStyle="SingleBorderWindow"
WindowStartupLocation="Manual" ShowActivated="False"
IsManipulationEnabled="False" mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="218" d:DesignWidth="368" SizeToContent="WidthAndHeight">
<Grid>
</Grid>
</Window>
My problem is that I’m not able to remove the title bar and close button completely. Or is there a library available for creating such windows?
I wanted to post screenshots, but I wasn’t able since I don’t have 10 reputation points, yet.
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅使用 WPF 无法做到这一点。您需要执行一些 Win32 互操作并从窗口中删除 WS_CAPTION 和 WS_SYSMENU 样式。
这是我的回答:一个类似的问题,其中有一些关于如何操作窗口样式和扩展样式的示例代码。
You can't do that with WPF only. You need to do some Win32 interop and remove the WS_CAPTION and WS_SYSMENU styles from your window.
Here's my answer to a similar SO question that has some sample code on how to manipulate the window style and extended style.
您可以将窗户设计成任何您想要的样子。除了已有的设置之外,将 WindowStyle 设置为 None 并将AllowsTransparency 设置为 true。然后,您可以将自己的 ControlTemplate 应用到 Window 并使其看起来像您能找到的任何东西,包括部分透明度和奇怪的形状。
You can make your window look like anything you want. Set WindowStyle to None and AllowsTransparency to true in addition to what you've got already. You can then apply your own ControlTemplate to Window and make it look like anything you can find, including partial transparency and weird shapes.