Wednesday, May 20, 2015

WPF Shellview Customizable WindowResizeGrip

//NOTE: This sample is for a WPF Main ShellView utilizing a fully customized header bar with Minimize & Maximize buttons, which allows the application user to grip the main form and resize to their heart's desire.

<Window x:Class="myApp.MainForm.Views.ShellView" IsEnabled="{Binding myBindingActivationVar,Mode=OneWay}"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

        ...
        WindowState="Maximized" WindowStyle="None" WindowStartupLocation="CenterScreen"
        SizeToContent="Manual" Icon="/myAppIcon.ico" Title="myApp MainForm" Padding="0" Margin="0" MinWidth="1000">

    <Window.Resources>       
        <Style x:Key="{x:Type Window}" TargetType="{x:Type Window}">
            <Setter Property="SnapsToDevicePixels" Value="true" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Window}">
                        <Grid>
                            <Grid.Background>
                                <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.WindowColorKey}}" />
                            </Grid.Background>
                            <AdornerDecorator>
                                <ContentPresenter />
                            </AdornerDecorator>
                            <ResizeGrip x:Name="WindowResizeGrip" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="Collapsed" IsTabStop="false" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="ResizeMode" Value="CanResizeWithGrip">
                                <Setter TargetName="WindowResizeGrip" Property="Visibility" Value="Visible" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
       
        ...
    </Window.Resources>       
   
    <Grid>
    <StackPanel MinHeight="600" MinWidth="1000" HorizontalAlignment="Stretch" Margin="0" Orientation="Vertical"> 
            <StackPanel.Background>
                <RadialGradientBrush>
                    <GradientStop Color="#FF80B3A4" />
                    <GradientStop Color="#FF458AA4" Offset="1.1" />
                </RadialGradientBrush>
            </StackPanel.Background>

            <!-- HEADER SECTION -->
            <Grid> ... <Grid/>

            <!-- MAIN SECTION -->
            <Grid> ... <Grid/>   

            <!-- FOOTER SECTION -->
            <Grid> ... <Grid/>     
    
    </StackPanel>
    </Grid>
           
           

No comments:

Post a Comment