WPF window with custom WindowChrome maximizes differently

492 views Asked by At

I have just started to use WindowChrome Class on a WPF window. I have noticed that when maximizing the window, it displays differently depending on whether I use the standard Chrome or the custom Chrome. Why?

I am double clicking the top of the window to maximize in both cases there is no code behind.

Here is the XAML - to add or remove the WindowChrome I am just deleting the Style property.

<Window
x:Class="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:local="clr-namespace:IPSurfer"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow"
Width="800"
Height="450"
Style="{DynamicResource ResourceKey=StandardStyle}"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<!--  Style="{DynamicResource ResourceKey=StandardStyle}"  -->
<Window.Resources>
    <Style x:Key="StandardStyle" TargetType="{x:Type local:MainWindow}">
        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome
                    CaptionHeight="50"
                    GlassFrameThickness="0"
                    ResizeBorderThickness="5" />
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MainWindow}">
                    <Grid>
                        <Border BorderBrush="PeachPuff" BorderThickness="5">
                            <Grid>
                                <ContentPresenter Content="{TemplateBinding Content}" />
                                <TextBlock
                                    Margin="10,8,0,0"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Top"
                                    Text="This is the new title" />
                            </Grid>
                        </Border>
                    </Grid>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
    <Border BorderBrush="Teal" BorderThickness="5">
        <Grid>

        </Grid>
    </Border>

</Grid>

NormalChromeNotMaximized Not Maximized, Standard Chrome - notice the Teal border

NormalChromeMaximized Maximized,Standard Chrome - this is showing the full Teal border fitting into the screen.

CustomChromeNotMaximized With the Window styled with the WindowChrome this is what it looks like not maximized. You see a border from my WindowChrome and the Teal border.

CustomChromeMaximized This is what it looks like maximized. My border in the Window Chrome is gone and only about half of the Teal border is there.

I also note that when I look at the Actual Width and Height of the Window when maximized the value is the same. It is just what is displayed is different.

0

There are 0 answers