2
votes

I am creating custom WPF Window using WindowChrome. I have my own style defined but title bar presents problem. If I set Background of my main Grid in template to Transparent then the whole window uses system accent colors and Maximize/Minimize/Close buttons are visible.

When I set any other background Maximize/Minimize/Close buttons get covered. I thought I just make my own, but those buttons are still clickable.

Is there any way to either show them or disable completely?

I can set CaptionHeight to 0 and create mi own title bar, but I don't want to reimplement drag and other default features.

My Style is below:

<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
Why don't you set GlassFrameThickness="0"? It's one of common settings to hide default buttons. - emoacht
Thanks, that solved the problem. Dunno how I managed to miss it :/ - Filip

1 Answers

4
votes

As @emoacht commented, seeing GlassFrameThickness to zero removes the invisible close/max/min buttons. You can still drag the window by the title area.

Setting GlassFrameThickness is intended to make the entire window glassy in that Aero way from Windows 7.

Also, you don't need to use the Microsoft.Windows.Shell NuGet package any more. The class you're after is in the framework now, as System.Windows.Shell.WindowChrome (in PresentationFramework.dll).