如何在WPF中使用不带Windows Aero玻璃效果的WindowChrome,黑色边框

编程入门 行业动态 更新时间:2024-10-19 06:23:14
本文介绍了如何在WPF中使用不带Windows Aero玻璃效果的WindowChrome,黑色边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用WindowChrome类自定义窗口边框。没有Windows Aero玻璃效果。不出所料,我最终选择了黑人。 但是我也最终没有字幕按钮

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

从Microsoft我了解到我可以通过将窗口样式设置为null来使用标准窗口来克服这些问题 msdn.microsoft /en-us/library/microsoft.windows.shell.windowchrome.aspx

From Microsoft i learn that i can use the standard window by setting the window style to null to overcome these problem msdn.microsoft/en-us/library/microsoft.windows.shell.windowchrome.aspx

但是我没有成功。

有人有这个可行的例子吗?还是某种可以解释如何解决我的问题的链接?

Do anyone have a working example of this? Or a link of some sort that can explain how to solve my problem?

我试图做一个简单的示例代码,并将WindowStyle更改为none,但无法正常工作。这是我的示例代码:

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="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/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>

推荐答案

我也在尝试WindowChrome,我的应用程序也可以正常工作到目前为止:

I'm experimenting with WindowChrome too and my application works so far:

<Window ...> <Window.Style> <Style TargetType="{x:Type Window}"> <Setter Property="shell:WindowChrome.WindowChrome"> <Setter.Value> <shell:WindowChrome CaptionHeight="15" CornerRadius="0" GlassFrameThickness="0,0,0,-1" NonClientFrameEdges="None" ResizeBorderThickness="5" UseAeroCaptionButtons="true"/> </Setter.Value> </Setter> </Style> </Window.Style> <!-- Add content to normal window content (not with template, at first) --> <Grid> </Grid> </Window>

如果您使用的是我的话,应该有一个空的窗口,除了标题按钮和玻璃窗外,别无其他上面的代码。

You should have an empty window with nothing more than the caption buttons and a glass window if you use my code above.

更多推荐

如何在WPF中使用不带Windows Aero玻璃效果的WindowChrome,黑色边框

本文发布于:2023-11-11 23:03:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579793.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:边框   不带   黑色   效果   玻璃

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!