P
P
Panicrust2013-11-19 06:18:43
WPF
Panicrust, 2013-11-19 06:18:43

Maximizing (Maximizing) a WPF Window

I am writing a program with design in the style of Windows 8 (Flat/Metro).
The main window MainWindow.xaml has properties -

WindowStyle="None"
AllowsTransparency="True"

The maximized (expanded) window occupies the entire screen, that is, the windows "taskbar" is also not visible. Is it possible to make some kind of indent from the bottom, or somehow "move" one layer back (as in Photoshop, for example). Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2013-11-19
@Panicrust

You can use Microsoft.Windows.Shell.WindowChrome.
FakeBorder is needed so that when the window is maximized, the client part does not go beyond the screen. I do not remember the source, I found it somewhere on the msdn forums.

<ControlTemplate x:Key="DefaultWindowTemplate" TargetType="{x:Type Window}">
        <Border Name="FakeBorder" BorderBrush="Green">
            <Border.Style>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="BorderThickness" Value="0"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=WindowState}" Value="Maximized">
                            <Setter Property="BorderThickness" Value="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowResizeBorderThickness}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
            <Border Name="WindowBorder" 
                Background="{TemplateBinding Background}" 
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}" Margin="0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="{StaticResource grdlenWindowCaptionHeight}" />
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Border Name="TitleBorder" Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}" >
                        <Grid >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="5" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <Image Margin="6,4,6,4" Source="{TemplateBinding Icon}" VerticalAlignment="Center"/>
                                <TextBlock VerticalAlignment="Center" Margin="0,0,0,0" Text="{TemplateBinding Title}" Style="{StaticResource WindowTitleTextBlock}" />
                            </StackPanel>
                            <Button Name="MinimizeButton"
                                    Grid.Column="1"           
                                    Margin="0"
                                    Style="{StaticResource ButtonWindowTitle}"                                 
                                    Command="{Binding Source={x:Static theme:ThemeCommands.Windows}, Path=MinWindow}"
                                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
                                <Path Data="{StaticResource iconWindowMinimize}"  Style="{StaticResource PathIcon9}"  />
                            </Button>
                            <Button Name="MaximizeButton"
                                    Grid.Column="2" 
                                    Style="{StaticResource ButtonWindowTitle}"                                 
                                    Command="{Binding Source={x:Static theme:ThemeCommands.Windows}, Path=MaxWindow}"
                                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
                                <Path Name="MaximizeIcon" Data="{StaticResource iconWindowMaximize}"  Style="{StaticResource PathIcon9}"/>
                            </Button>
                            <Button Name="CloseButton"
                                    Grid.Column="3"                                     
                                    Style="{StaticResource ButtonWindowTitle}"                                 
                                    Command="{Binding Source={x:Static theme:ThemeCommands.Windows}, Path=CloseWindow}"
                                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
                                <Path Data="{StaticResource iconWindowClose}" Style="{StaticResource PathIcon9}" />
                            </Button>
                        </Grid>
                    </Border>

                    <ContentPresenter Margin="0" Grid.Row="1" Content="{TemplateBinding Content}"/>
                </Grid>
            </Border>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="WindowState" Value="Maximized">
                <Setter TargetName="MaximizeIcon" Property="Data" Value="{StaticResource iconWindowRestore}" />
            </Trigger>
            <Trigger Property="IsActive" Value="False">
                <Setter TargetName="WindowBorder" Property="BorderBrush" Value="{StaticResource WindowBorderInactiveBrush}" />
            </Trigger>
            <Trigger Property="WindowStyle" Value="ToolWindow">
                <Setter TargetName="MinimizeButton" Property="Visibility" Value="Hidden" />
                <Setter TargetName="MaximizeButton" Property="Visibility" Value="Hidden" />
            </Trigger>
            <Trigger Property="WindowStyle" Value="ThreeDBorderWindow">
                <Setter Property="BorderThickness" Value="7" />
            </Trigger>
            <Trigger Property="WindowStyle" Value="None">
                <Setter TargetName="MinimizeButton" Property="Visibility" Value="Hidden" />
                <Setter TargetName="MaximizeButton" Property="Visibility" Value="Hidden" />
                <Setter TargetName="CloseButton" Property="Visibility" Value="Hidden" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

<Style x:Key="WindowDefault" TargetType="{x:Type Window}">
        <Setter Property="Background" Value="{StaticResource WindowBackgroundBrush}" />
        <Setter Property="Foreground" Value="{StaticResource ControlForegroundBrush}" />
        <Setter Property="BorderBrush" Value="{StaticResource AccentBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="FontFamily" Value="{StaticResource DefaultFont}"/>
        <Setter Property="FontSize" Value="{StaticResource DefaultFontSize}" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="shell:WindowChrome.WindowChrome">
            <Setter.Value>
                <shell:WindowChrome
                        ResizeBorderThickness="6"
                        CaptionHeight="{StaticResource WindowCaptionHeight}"
                        CornerRadius="0"                    
                        GlassFrameThickness="0,0,0,1"/>
            </Setter.Value>
        </Setter>
        <Setter Property="Template" Value="{DynamicResource DefaultWindowTemplate}"/>        
    </Style>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question