2012-05-22 116 views
4

我是WPF中的新手,我想製作一個具有最大尺寸(顯示器尺寸)的窗口。WPF窗口大小有顯示器大小

窗口的XAML代碼是這樣的:

Stop a = new Stop();     
a.Show(); 
a.Width = System.Windows.SystemParameters.PrimaryScreenWidth; 
a.Height = System.Windows.SystemParameters.PrimaryScreenHeight; 

我如何設置窗口大小顯示器尺寸:打開這個窗口是這樣的

<Window x:Class="WpfApplication1.Stop" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="Stop" Height="{Binding}" Width="{Binding}" Background="Black" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="NoResize" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="260" d:DesignWidth="348" SizeToContent="WidthAndHeight"> 
    <Grid> 
     <Button Content="Ok" Height="25" HorizontalAlignment="Left" Margin="194,36,0,0" Name="button1" VerticalAlignment="Top" Width="38" Click="button1_Click" /> 
     <TextBlock Height="17" HorizontalAlignment="Left" Margin="18,16,0,0" Name="textBlock1" Text="Introduceti parola:" VerticalAlignment="Top" Width="246" FontSize="14" Foreground="White" /> 
     <PasswordBox Height="25" HorizontalAlignment="Left" Margin="12,36,0,0" Name="passwordBox1" VerticalAlignment="Top" Width="176" /> 
    </Grid> 
</Window> 

的C#代碼?

回答

9

使用這種代碼隱藏:

a.WindowState = WindowState.Maximized; 
XAML

,並刪除SizeToContent

有了這個代碼:

a.Width = System.Windows.SystemParameters.PrimaryScreenWidth; 
a.Height = System.Windows.SystemParameters.PrimaryScreenHeight; 

使用具有不同分辨率的次畫面時,你就會有問題。

1

上面的評論工作。我做了以下: - 寫在mainwindow.xaml.cs中: -

public MainWindow() 
     { 
      this.WindowState = WindowState.Maximized; 
      InitializeComponent(); 
     }