2012-05-22 4 views
4

Je suis nouveau dans WPF et je veux faire une fenêtre qui a des tailles maximales (tailles d'écran).WPF Taille de la fenêtre ont la taille du moniteur

Code XAML de la fenêtre est la suivante:

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

Le code C# ouvrir cette fenêtre est la suivante:

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

Comment puis-je définir la taille de la fenêtre pour surveiller la taille?

Répondre

9

utiliser dans le code-behind:

a.WindowState = WindowState.Maximized; 

et retirez SizeToContent de votre XAML.

Avec ce code:

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

vous aurez des problèmes lors de l'utilisation écran secondaire avec une résolution différente.

1

Le commentaire ci-dessus fonctionne. J'ai fait ci-dessous: - écrit dans mainwindow.xaml.cs: -

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