Panicrust
@Panicrust

Максимизация (развёртывание) окна WPF

Пишу программу с дизайном в стиле Windows 8 (Flat/Metro).
У главного окна MainWindow.xaml заданы свойства -
WindowStyle="None"
AllowsTransparency="True"

Максимизированное (развёрнутое) окно занимает полностью весь экран, то есть "Панели задач" windows тоже не видно. Можно ли сделать какой-то отступ снизу, либо как-то "отодвинуть" на один слой назад (как в фотошопе, например). Заранее благодарю
  • Вопрос задан
  • 4750 просмотров
Решения вопроса 1
Можно использовать Microsoft.Windows.Shell.WindowChrome.
FakeBorder нужен для того, чтобы при развертывании окна клиентская часть не выходила за пределы экрана. Источник не помню, где-то на форумах msdn нашел.
<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>
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы