I Have created a custom window in WPF using rectangles with This Link refrence My issue with maximize button click, I have done alot of R&D for maximizing that with neatness below is the code for maximize:
this.RectMain.Width = SystemParameters.WorkArea.Width;
//this.RectMain.Height = System.Windows.SystemParameters.VirtualScreenHeight - 35;
this.RectMain.Height = SystemParameters.WorkArea.Height;
this.RectTitleBar.Width = SystemParameters.WorkArea.Width;
this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
//this.RectTitleBar.Height = SystemParameters.WorkArea.Height;
this.dockMenu.Width = SystemParameters.WorkArea.Width;
this.frmContent1.Width = SystemParameters.WorkArea.Width;
this.WindowState = WindowState.Maximized;
When I maximize the window it used get little inside above the screen Please someone suggest any solution to set the form maximized like normal window form gets maximized. Below is my Main FromCode:
<Window x:Class="WPFNavigation.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" WindowStyle="None" Background="Transparent"
WindowStartupLocation="CenterScreen" AllowsTransparency="True" Loaded="Window_Loaded_1">
<Window.CommandBindings>
<CommandBinding Command="NavigationCommands.GoToPage" Executed="GoToPageExecuteHandler" CanExecute="GoToPageCanExecuteHandler"/>
</Window.CommandBindings>
<Window.Resources>
<Style x:Key="MyButton" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.8" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Rectangle Name="RectMain" Height="539" Stroke="Black" VerticalAlignment="Top" Margin="2,1,1,-5" Fill="White" StrokeThickness="0"/>
<Canvas>
<Rectangle x:Name="RectTitleBar" Canvas.Top="0" Canvas.Right="0" Fill="White" Height="19" Stroke="Black" Width="763" StrokeThickness="0" MouseDown="RectTitleBar_MouseDown" Canvas.Left="4"/>
<Button x:Name="MinimizeButton" BorderBrush="Transparent" Style="{StaticResource MyButton}" Canvas.Right="57" Canvas.Top="4" Width="20" Height="12" Click="MinimizeButton_Click">
<Button.Background>
<ImageBrush ImageSource="Resources/Minimize.png"></ImageBrush>
</Button.Background>
</Button>
<Button x:Name="MaximizeButton" Style="{StaticResource MyButton}" BorderBrush="Transparent" Canvas.Right="30" Canvas.Top="4" Width="20" Height="12" Click="MaximizeButton_Click">
<Button.Background>
<ImageBrush ImageSource="Resources\Maximize.png"></ImageBrush>
</Button.Background>
</Button>
<Button x:Name="CloseButton" Style="{StaticResource MyButton}" BorderBrush="Transparent" Canvas.Right="2" Canvas.Top="4" Width="20" Height="12" Click="CloseButton_Click">
<Button.Background>
<ImageBrush ImageSource="Resources/Close.png"></ImageBrush>
</Button.Background>
</Button>
<TextBlock Canvas.Left="5" FontWeight="ExtraBold" TextWrapping="Wrap" Text="Airport Portal" Canvas.Top="0"/>
<DockPanel Canvas.Top="20" Name="dockMenu" Grid.RowSpan="2" Width="763">
<Menu Name="MainMenu" VerticalAlignment="Top" FontSize="16" BorderThickness="1"
FontWeight="Bold" Height="28" DockPanel.Dock="Top" Foreground="White">
<Menu.BitmapEffect>
<OuterGlowBitmapEffect></OuterGlowBitmapEffect>
</Menu.BitmapEffect>
<Menu.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FF3A60AD" Offset="0.528"/>
<GradientStop Color="#FF6A85D8" Offset="0.01"/>
<GradientStop Color="#FF3464C4" Offset="1"/>
<GradientStop Color="#FF202E7E" Offset="1"/>
</LinearGradientBrush>
</Menu.Background>
<MenuItem Header="Home" Command="NavigationCommands.GoToPage" CommandParameter="Pages/Home.xaml" CommandTarget="{Binding ElementName=frmContent}" />
<MenuItem Header="Masters" >
<MenuItem.ToolTip>
<ToolTip>
Masters
</ToolTip>
</MenuItem.ToolTip>
<MenuItem Name="submenuEmp" Background="#FF3A60AD" Header="Employee Master">
<MenuItem.Icon>
<Image Width="20" Height="20" Source="C:\Apps\R&D\WPFNavigation\WPFNavigation\Images\Employee_Master.ico" />
</MenuItem.Icon>
<MenuItem.ToolTip>
<ToolTip>
Employee Master
</ToolTip>
</MenuItem.ToolTip>
<MenuItem Name="SubsubmenuEmp" Header="Create Employee" Command="NavigationCommands.GoToPage" CommandParameter="EmpMaster.xaml" CommandTarget="{Binding ElementName=frmContent}" Background="#FF3A60AD" >
<MenuItem.ToolTip>
<ToolTip>
Create Employee
</ToolTip>
</MenuItem.ToolTip>
</MenuItem>
</MenuItem>
</MenuItem>
<MenuItem Header="Page 3" Command="NavigationCommands.GoToPage" CommandParameter="Pages/Home.xaml" CommandTarget="{Binding ElementName=frmContent}" />
<MenuItem Header="Page without master" Command="NavigationCommands.GoToPage" CommandParameter="Pages/Home.xaml" CommandTarget="{Binding ElementName=frmContent}" Width="174" />
</Menu>
<Frame NavigationUIVisibility="Visible" Name="frmContent1" Grid.Column="0" Grid.Row="1" Source="Pages/Home.xaml" Width="764" />
</DockPanel>
</Canvas>
</Grid>