WPF适合窗口大小

时间:2014-09-16 04:20:27

标签: c# wpf

我是WPF的新手,我正在开发一个具有不同图像,文本框等的应用程序。问题出现在我的屏幕上,根据窗口的大小,所有看起来都很好,并且已在加载的窗口上设置了属性:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        Width = System.Windows.SystemParameters.PrimaryScreenWidth;
        Height = System.Windows.SystemParameters.PrimaryScreenHeight;
    }

在我的屏幕上使用该应用程序时,它看起来像这样:

enter image description here

但是当在平板电脑上使用它时,我看不到日历,也没有看到“Fecha nacimiento”的文字。这是我正在使用的WPF代码:

<Window x:Class="BiometricoRegistro.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="RegistrarCliente"  Height="978" Width="1600" Loaded="Window_Loaded" WindowState="Maximized">
    <Grid>
        <Grid.Background>
            <ImageBrush ImageSource="Imagenes\home_bg.jpg"/>
        </Grid.Background>
        <TextBox x:Name="txtbRut" HorizontalAlignment="Left" Height="51" TextWrapping="Wrap" BorderBrush="Transparent" VerticalAlignment="Top" Width="379" Margin="30,230,0,0" FontSize="35" FontWeight="Bold" PreviewTextInput="txtbRut_PreviewTextInput">
            <TextBox.Background>
                <ImageBrush ImageSource="Imagenes\input.png"/>
            </TextBox.Background>
        </TextBox>
        <TextBox x:Name="txtbRutVer" HorizontalAlignment="Left" Height="51" TextWrapping="Wrap" BorderBrush="Transparent" VerticalAlignment="Top" Width="74" Margin="430,230,0,0" FontSize="35" FontWeight="Bold" TextAlignment="Center">
            <TextBox.Background>
                <ImageBrush ImageSource="Imagenes\input.png"/>
            </TextBox.Background>
        </TextBox>
        <TextBox x:Name="txtbNombre" HorizontalAlignment="Left" Height="51" TextWrapping="Wrap" BorderBrush="Transparent" VerticalAlignment="Top" Width="474" Margin="30,330,0,0" FontSize="35" FontWeight="Bold">
            <TextBox.Background>
                <ImageBrush ImageSource="Imagenes\input.png"/>
            </TextBox.Background>
        </TextBox>
        <TextBox x:Name="txtbApellido" HorizontalAlignment="Left" Height="51" TextWrapping="Wrap" BorderBrush="Transparent" VerticalAlignment="Top" Width="474" Margin="30,430,0,0" FontSize="35" FontWeight="Bold">
            <TextBox.Background>
                <ImageBrush ImageSource="Imagenes\input.png"/>
            </TextBox.Background>
        </TextBox>
        <TextBox x:Name="txtbEmail" HorizontalAlignment="Left" Height="51" TextWrapping="Wrap" BorderBrush="Transparent" VerticalAlignment="Top" Width="474" Margin="30,530,0,0" FontSize="35" FontWeight="Bold">
            <TextBox.Background>
                <ImageBrush ImageSource="Imagenes\input.png"/>
            </TextBox.Background>
        </TextBox>
        <Calendar x:Name="calendar" HorizontalAlignment="Left" Height="170" VerticalAlignment="Top" Width="260" Margin="0,720,0,57"/>
        <Button x:Name="btnRegistrar" Content="Registrar" HorizontalAlignment="Center" Height="118" VerticalAlignment="Center" Width="296" Margin="775,0,221,100" Click="btnRegistrar_Click"/>
        <ComboBox x:Name="cbPorcentaje" HorizontalAlignment="Left" Height="40" Margin="30,630,0,0" VerticalAlignment="Top" Width="230" HorizontalContentAlignment="Center" FontSize="35">
            <ComboBoxItem Content="A" FontSize="35"></ComboBoxItem>
            <ComboBoxItem Content="B" FontSize="35"></ComboBoxItem>
            <ComboBoxItem Content="C" FontSize="35"></ComboBoxItem>
        </ComboBox>
        <TextBlock HorizontalAlignment="Left" Height="37" Margin="30,176,0,0" TextWrapping="Wrap" Text="Rut cliente" VerticalAlignment="Top" Width="474" FontFamily="/BiometricoRegistro;component/Fonts/#Alex Brush" FontSize="36" Foreground="White"/>
        <TextBlock HorizontalAlignment="Left" Height="37" Margin="30,286,0,0" TextWrapping="Wrap" Text="Nombres cliente" VerticalAlignment="Top" Width="474" FontFamily="/BiometricoRegistro;component/Fonts/#Alex Brush" FontSize="36" Foreground="White"/>
        <TextBlock HorizontalAlignment="Left" Height="37" Margin="30,386,0,0" TextWrapping="Wrap" Text="Apellidos cliente" VerticalAlignment="Top" Width="474" FontFamily="/BiometricoRegistro;component/Fonts/#Alex Brush" FontSize="36" Foreground="White"/>
        <TextBlock HorizontalAlignment="Left" Height="37" Margin="30,486,0,0" TextWrapping="Wrap" Text="Email cliente" VerticalAlignment="Top" Width="474" FontFamily="/BiometricoRegistro;component/Fonts/#Alex Brush" FontSize="36" Foreground="White"/>
        <TextBlock HorizontalAlignment="Left" Height="37" Margin="30,586,0,0" TextWrapping="Wrap" Text="Tipo Descuento" VerticalAlignment="Top" Width="474" FontFamily="/BiometricoRegistro;component/Fonts/#Alex Brush" FontSize="36" Foreground="White"/>
        <TextBlock HorizontalAlignment="Left" Height="37" Margin="30,678,0,230" TextWrapping="Wrap" Text="Fecha nacimiento" VerticalAlignment="Top" Width="474" FontFamily="/BiometricoRegistro;component/Fonts/#Alex Brush" FontSize="36" Foreground="White"/>
        <TextBlock x:Name="txtResult" HorizontalAlignment="Left" Height="64" Margin="501,0,0,57" TextWrapping="Wrap" Text="" VerticalAlignment="Bottom" Width="823" FontSize="46" Foreground="Red" FontFamily="PMingLiU-ExtB"/>
    </Grid>
</Window>

1 个答案:

答案 0 :(得分:2)

  1. 始终使用合适的面板。我更喜欢Dock和stackpanel与分离器。
  2. 将System.Windows.Window.SizeToContent分配给System.Windows.SizeToContent.WidthAndHeight。
  3. 使用Resource Dictonary获取边距和其他值的一致性
  4. 我不想使用绝对位置。根据您的内容确定您的保证金值。