C# WPF WindowChrome带背景-系统按钮隐藏
我正在使用WindowChrome创建自定义WPF窗口。我有自己的风格定义,但标题栏出现了问题。如果我在模板中将主网格的背景设置为透明,则整个窗口使用系统强调色,并且可以看到最大化/最小化/关闭按钮 当我设置任何其他背景时,最大化/最小化/关闭按钮被覆盖。我以为我自己做的,但那些按钮仍然可以点击 有没有办法显示它们或完全禁用它们 我可以将CaptionHeight设置为0并创建自己的标题栏,但我不想重新实现拖动和其他默认功能 我的风格如下:C# WPF WindowChrome带背景-系统按钮隐藏,c#,wpf,window-chrome,C#,Wpf,Window Chrome,我正在使用WindowChrome创建自定义WPF窗口。我有自己的风格定义,但标题栏出现了问题。如果我在模板中将主网格的背景设置为透明,则整个窗口使用系统强调色,并且可以看到最大化/最小化/关闭按钮 当我设置任何其他背景时,最大化/最小化/关闭按钮被覆盖。我以为我自己做的,但那些按钮仍然可以点击 有没有办法显示它们或完全禁用它们 我可以将CaptionHeight设置为0并创建自己的标题栏,但我不想重新实现拖动和其他默认功能 我的风格如下: <Window.Style>
<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按钮。您仍然可以将窗口拖动到标题区域 设置GlassFrameThickness的目的是使整个窗口从Windows7以空气动力学的方式呈现玻璃状
此外,您不需要再使用。您要查找的类现在位于框架中,如PresentationFramework.dll中的System.Windows.Shell.WindowChrome。为什么不将GlassFrameThickness设置为0?隐藏默认按钮是常用设置之一。谢谢,这解决了问题。不知道我是怎么错过的:/