如何使用常规字幕按钮在 Non-Client 区域正确绘制内容
How to Draw Content in Non-Client Area Properly with Regular Caption Buttons
我正在尝试制作一个带有默认标题按钮和标题栏的 window,并且仍然能够在 window chrome 中放置任意内容;但是,我尝试过的所有解决方案都在标题按钮右侧留出大约 5 个单位的边距。这是一个基本示例:
<Window x:Class="SemiCustomWindowChrome.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SemiCustomWindowChrome"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Name="Window">
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="True" ResizeBorderThickness="5" GlassFrameThickness="1,28,1,1"/>
</WindowChrome.WindowChrome>
<Window.Template>
<ControlTemplate>
<AdornerDecorator>
<ContentPresenter Content="{Binding ElementName=Window, Path=Content}"/>
</AdornerDecorator>
</ControlTemplate>
</Window.Template>
<Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<Button Content="Click me daddy!" WindowChrome.IsHitTestVisibleInChrome="True" Height="28"/>
<TextBlock Text="Custom Window Test" Margin="6.5"/>
</StackPanel>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontFamily="MS Calibri" FontWeight="ExtraLight" Text="Hello There"/>
</Grid>
以上代码产生this.
为了清楚起见,我想删除 window chrome 中标题按钮右侧的白色填充,以便 window 与任何内容完全相同其他,唯一的区别是我可以将控件放在 non-client 区域(window chrome)。
感谢所有帮助!
如果有更稳定的 DWM 方法,不包括使用 WindowChrome 元素,如果有人能给我一个例子,我将不胜感激。
WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="0.5,28,0,0.5" NonClientFrameEdges="Right"/>
</WindowChrome.WindowChrome>
<Window.Template>
<ControlTemplate>
<ContentPresenter Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Content}"/>
</ControlTemplate>
</Window.Template>
这花了很长时间才找到。本来我以为WindowChrome class 只是完全坏了,在一定程度上,但我还是设法使用了它。我想出的其他解决方案要复杂得多,最终,尝试和 WindowChrome 混在一起似乎要容易得多。我将专门针对 Windows 10 开发 class 的修改版本,但在此之前,这是可行的。我希望这对某人有所帮助。
要使用此代码,只需将其放在 XAML 中内容区域的顶部,以获得 window。
我正在尝试制作一个带有默认标题按钮和标题栏的 window,并且仍然能够在 window chrome 中放置任意内容;但是,我尝试过的所有解决方案都在标题按钮右侧留出大约 5 个单位的边距。这是一个基本示例:
<Window x:Class="SemiCustomWindowChrome.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SemiCustomWindowChrome"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Name="Window">
<WindowChrome.WindowChrome>
<WindowChrome UseAeroCaptionButtons="True" ResizeBorderThickness="5" GlassFrameThickness="1,28,1,1"/>
</WindowChrome.WindowChrome>
<Window.Template>
<ControlTemplate>
<AdornerDecorator>
<ContentPresenter Content="{Binding ElementName=Window, Path=Content}"/>
</AdornerDecorator>
</ControlTemplate>
</Window.Template>
<Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<Button Content="Click me daddy!" WindowChrome.IsHitTestVisibleInChrome="True" Height="28"/>
<TextBlock Text="Custom Window Test" Margin="6.5"/>
</StackPanel>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontFamily="MS Calibri" FontWeight="ExtraLight" Text="Hello There"/>
</Grid>
以上代码产生this.
为了清楚起见,我想删除 window chrome 中标题按钮右侧的白色填充,以便 window 与任何内容完全相同其他,唯一的区别是我可以将控件放在 non-client 区域(window chrome)。 感谢所有帮助!
如果有更稳定的 DWM 方法,不包括使用 WindowChrome 元素,如果有人能给我一个例子,我将不胜感激。
WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="0.5,28,0,0.5" NonClientFrameEdges="Right"/>
</WindowChrome.WindowChrome>
<Window.Template>
<ControlTemplate>
<ContentPresenter Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Content}"/>
</ControlTemplate>
</Window.Template>
这花了很长时间才找到。本来我以为WindowChrome class 只是完全坏了,在一定程度上,但我还是设法使用了它。我想出的其他解决方案要复杂得多,最终,尝试和 WindowChrome 混在一起似乎要容易得多。我将专门针对 Windows 10 开发 class 的修改版本,但在此之前,这是可行的。我希望这对某人有所帮助。
要使用此代码,只需将其放在 XAML 中内容区域的顶部,以获得 window。