如何在 wpf 中使用 WindowChrome 而不使用 Windows Aero 玻璃效果,黑色边框
我正在尝试使用 WindowChrome 类自定义窗口边框。没有 Windows Aero 玻璃效果。正如预期的那样,我最终得到了一个黑人寄宿生。 但我最终也没有标题按钮
从微软我了解到我可以通过将窗口样式设置为 null 来使用标准窗口来克服这些问题 http://msdn.microsoft.com/en- us/library/microsoft.windows.shell.windowchrome.aspx
但我没有成功。
有人有这方面的工作示例吗?或者某种可以解释如何解决我的问题的链接?
我尝试编写一个简单的示例代码,并将 WindowStyle 更改为 none,但它不起作用。这是我的示例代码:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell" Title="Window" Height="400" Width="500">
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid>
<Border Background="White" Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
<ContentPresenter Content="{TemplateBinding Content}" />
</Border>
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}"
VerticalAlignment="Top" HorizontalAlignment="Left"
Margin="36,8,0,0"/>
<Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}"
VerticalAlignment="Top" HorizontalAlignment="Left"
Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}"
Width="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=SmallIconSize.Width}"
shell:WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Style>
<Grid/>
</Window>
I'm trying to customize a window border by using the WindowChrome class. Without Windows Aero glass effects. As expected I end up with a black boarder.
But i also end up without caption buttons
From Microsoft i learn that i can use the standard window by setting the window style to null to overcome these problem
http://msdn.microsoft.com/en-us/library/microsoft.windows.shell.windowchrome.aspx
But i do not succeed with that.
Do anyone have a working example of this? Or a link of some sort that can explain how to solve my problem?
I have tried to do a simple example code, and change the WindowStyle to none but it wont work. This is my example code:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell" Title="Window" Height="400" Width="500">
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid>
<Border Background="White" Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
<ContentPresenter Content="{TemplateBinding Content}" />
</Border>
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}"
VerticalAlignment="Top" HorizontalAlignment="Left"
Margin="36,8,0,0"/>
<Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}"
VerticalAlignment="Top" HorizontalAlignment="Left"
Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}"
Width="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=SmallIconSize.Width}"
shell:WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Style>
<Grid/>
</Window>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也在尝试 WindowChrome,到目前为止,我的应用程序工作正常:
如果您使用上面的代码,您应该有一个空窗口,只有标题按钮和一个玻璃窗口。
I'm experimenting with WindowChrome too and my application works so far:
You should have an empty window with nothing more than the caption buttons and a glass window if you use my code above.