带背景的 WPF WindowChrome - 系统按钮被隐藏
WPF WindowChrome with background - system buttons are hidden
我正在使用 WindowChrome
创建自定义 WPF Window。我定义了自己的样式,但标题栏出现问题。如果我将模板中主要 Grid
的 Background
设置为透明,则整个 window 使用系统强调色并且 Maximize/Minimize/Close
按钮可见。
当我设置任何其他背景时 Maximize/Minimize/Close
按钮被覆盖。我以为我只是自己制作,但这些按钮仍然可以点击。
有什么方法可以显示它们或完全禁用它们吗?
我可以将 CaptionHeight
设置为 0 并创建我自己的标题栏,但我不想重新实现拖动和其他默认功能。
我的风格如下:
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome GlassFrameThickness="-1"
ResizeBorderThickness="4"
CaptionHeight="36"/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ConfigurationWindow}" >
<Grid>
<Rectangle Fill="Blue" VerticalAlignment="Top" Width="{TemplateBinding Width}"
Height="35" ></Rectangle>
<!-- This is the ContentPresenter that displays the window content. -->
<Border Margin="0,40,0,5" >
<ContentPresenter Content="{TemplateBinding Content}"/>
</Border>
<!--This is the transparent white rectangle that goes behind the window content.-->
<Border Margin="1,40,1,5" BorderBrush="Gray" BorderThickness="0,1,0,1"
Grid.ZIndex="-1">
<Rectangle Fill="White" Opacity="0.5" />
</Border>
<!-- Window Title -->
<TextBlock VerticalAlignment="Top" TextAlignment="Center"
Padding="0,3,0,8"
Text="{Binding RelativeSource=
{RelativeSource TemplatedParent}, Path=Title}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Style>
正如@emoacht 评论的那样,看到 GlassFrameThickness
归零会删除不可见的 close/max/min 按钮。您仍然可以通过标题区域拖动 window。
设置 GlassFrameThickness
旨在使整个 window 从 Windows 7.
此外,您不再需要使用 Microsoft.Windows.Shell
NuGet package。您所追求的 class 现在在框架中,如 System.Windows.Shell.WindowChrome
(在 PresentationFramework.dll
中)。
我正在使用 WindowChrome
创建自定义 WPF Window。我定义了自己的样式,但标题栏出现问题。如果我将模板中主要 Grid
的 Background
设置为透明,则整个 window 使用系统强调色并且 Maximize/Minimize/Close
按钮可见。
当我设置任何其他背景时 Maximize/Minimize/Close
按钮被覆盖。我以为我只是自己制作,但这些按钮仍然可以点击。
有什么方法可以显示它们或完全禁用它们吗?
我可以将 CaptionHeight
设置为 0 并创建我自己的标题栏,但我不想重新实现拖动和其他默认功能。
我的风格如下:
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome GlassFrameThickness="-1"
ResizeBorderThickness="4"
CaptionHeight="36"/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ConfigurationWindow}" >
<Grid>
<Rectangle Fill="Blue" VerticalAlignment="Top" Width="{TemplateBinding Width}"
Height="35" ></Rectangle>
<!-- This is the ContentPresenter that displays the window content. -->
<Border Margin="0,40,0,5" >
<ContentPresenter Content="{TemplateBinding Content}"/>
</Border>
<!--This is the transparent white rectangle that goes behind the window content.-->
<Border Margin="1,40,1,5" BorderBrush="Gray" BorderThickness="0,1,0,1"
Grid.ZIndex="-1">
<Rectangle Fill="White" Opacity="0.5" />
</Border>
<!-- Window Title -->
<TextBlock VerticalAlignment="Top" TextAlignment="Center"
Padding="0,3,0,8"
Text="{Binding RelativeSource=
{RelativeSource TemplatedParent}, Path=Title}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Style>
正如@emoacht 评论的那样,看到 GlassFrameThickness
归零会删除不可见的 close/max/min 按钮。您仍然可以通过标题区域拖动 window。
设置 GlassFrameThickness
旨在使整个 window 从 Windows 7.
此外,您不再需要使用 Microsoft.Windows.Shell
NuGet package。您所追求的 class 现在在框架中,如 System.Windows.Shell.WindowChrome
(在 PresentationFramework.dll
中)。