WPF WindowChrome带有背景 - 系统按钮被隐藏

3
我正在使用WindowChrome创建自定义的WPF窗口。我已经定义了自己的样式,但标题栏出现了问题。如果我将模板中主要GridBackground设置为透明,则整个窗口使用系统强调颜色,且最大化/最小化/关闭按钮可见。
当我设置任何其他背景时,最大化/最小化/关闭按钮会被覆盖。我本以为只需要创建我的按钮,但是这些按钮仍然是可点击的。
有没有办法显示它们或完全禁用它们?
我可以将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>

1
为什么不设置GlassFrameThickness="0"呢?这是隐藏默认按钮的常见设置之一。 - emoacht
谢谢,问题解决了。不知道我怎么会错过它 :/ - Filip
1个回答

4
如@emoacht所述,将GlassFrameThickness设置为零会移除不可见的关闭/最大化/最小化按钮。您仍然可以通过标题区域拖动窗口。
设置GlassFrameThickness旨在使整个窗口像Windows 7中的Aero一样具有玻璃效果。
此外,您不再需要使用Microsoft.Windows.Shell NuGet包。您需要的类现在在框架中,名为System.Windows.Shell.WindowChrome(在PresentationFramework.dll中)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接