0

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&amp;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>

Community
  • 1
  • 1
Nadeem Shaikh
  • 117
  • 14

1 Answers1

0

This should do the trick and maximize your form:

 <Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525"  WindowState="Maximized" 
WindowStyle="None">

Only these properties! dont use anything else.

Goodluck.

Slashy
  • 1,841
  • 3
  • 23
  • 42
  • I have set WindowStyle="None" and Background="Transparent" and used rectangle for form display and trying to maximized that rectangle in windows application – Nadeem Shaikh Aug 25 '15 at 11:09
  • @user3698716 oh is it wpf? ? – Slashy Aug 25 '15 at 11:10
  • Yup, I have mentioned in the title only – Nadeem Shaikh Aug 25 '15 at 11:12
  • @user3698716 alright. .You just want to maximize your window right? Why do you use rectangle? In which context do you need it? – Slashy Aug 25 '15 at 11:13
  • I have set window style to none to disable Title bar and create own designed titlebar, To achieve that I have used rectangles, Request you to go through the link which I have shared in the question. Same approach I have followed which shown in the link – Nadeem Shaikh Aug 25 '15 at 11:16
  • @user3698716 oh i understand see my edited answer and if i helped you may you mark it please? :D – Slashy Aug 25 '15 at 11:38
  • Almost same thing I also have done, There is no problem for maximizing window, but the rectangle which is place inside the window that needs to be maximized like a window. My actual window set to borderless and background transparent, So Now my rectangle acting like a window, I wish to maximize that rectangle according to the client screen height and width. – Nadeem Shaikh Aug 25 '15 at 11:42
  • @user3698716 alright. could you show some of your xaml code here? i would glad to help you but i cannot do nothing without some pieces of code. just post here (edit your question) the main xaml – Slashy Aug 25 '15 at 11:43
  • Hey Slashy I Have updated question with xaml page code. Please check and help me out – Nadeem Shaikh Aug 25 '15 at 11:49
  • Can someone help me to get rid off this please? – Nadeem Shaikh Aug 26 '15 at 14:47