2015-08-25 470 views
0

我創建使用矩形在WPF自定義窗口This Link refrence 我的問題與最大化按鈕點擊整齊最大化,我已經做了很多 - [R & d的最大化,與整潔下面是代碼爲最大化:WPF自定義Windows無法設置窗口

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; 

當我將窗口最大化它曾經讓小屏幕裏 以上請人提出任何解決方案來最大化像普通窗口的形式獲取最大化的形式。 下面是我的主要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> 

+0

你刪除窗口邊框時,它得到最大化?這是所有標準窗口所具有的行爲。 – Nipheris

+0

我已經設置WindowStyle =「無」和背景=「透明」 –

回答

0

這應該做的伎倆,並最大限度地提高您的形式:

<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"> 

只有這些屬性!別用別的東西。

Goodluck。

+0

我已經設置WindowStyle =「無」和背景=「透明」和使用矩形爲形式的顯示並試圖最大化該矩形在窗戶應用 –

+0

@ user3698716哦是它wpf? ? – Slashy

+0

是啊,我在標題中唯一 –