2011-06-05 8 views
2

Lorsque la fenêtre d'application est redimensionnée, je souhaite que les éléments qu'elle contient soient également redimensionnés proportionnellement. Est-ce possible? J'ai essayé de googler, mais je ne pouvais pas vraiment trouver quelque chose à ce sujet. Mon code XAML:Éléments de redimensionnement automatique WPF

<Window x:Class="app.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" KeyDown="Window_KeyDown"> 
    <Grid> 
     <TabControl Name="MyTabControl"> 
      <TabItem Name="pradzia" Header="Pradžia" IsSelected="True"> 
       <Button Content="Pradžia" Height="55" Name="button1" Width="125" Click="button1_Click" /> 
      </TabItem> 
      <TabItem Header="Vykdyti" Name="vykdyti" IsEnabled="False"> 
        <Grid Button.Click="Grid_Click"> 
        <Button Content="1" Height="50" HorizontalAlignment="Left" Margin="6,0,0,6" Name="button2" VerticalAlignment="Bottom" Width="125" FontSize="20" /> 
         <Button Content="2" Height="50" HorizontalAlignment="Center" Name="button3" VerticalAlignment="Bottom" Width="125" FontSize="20" Margin="184,0,184,6" /> 
        <Button Content="3" Height="50" HorizontalAlignment="Right" Margin="362,0,0,6" Name="button4" VerticalAlignment="Bottom" Width="125" FontSize="20" /> 
         <TextBlock Height="23" HorizontalAlignment="Center" Name="textBlock1" Margin="0,15,0,0" Text="Kiek gyvūnų paveiksliuke?" VerticalAlignment="Top" FontSize="16" /> 
        <Image Height="150" HorizontalAlignment="Center" Margin="0,-25,0,0" Name="mainImage" Stretch="Uniform" VerticalAlignment="Center" Width="200" /> 
       </Grid> 
      </TabItem> 
     </TabControl> 
    </Grid> 
</Window> 

Répondre

3

Vous semblez utiliser une grille sans utiliser réellement la fonctionnalité prime: Lignes & Colonnes
En les utilisant, vous pouvez faire la mise en page allouer de l'espace proportially en définissant des lignes et des colonnes étoile de taille .

par exemple.

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="3*"/> 
     <ColumnDefinition Width="2*"/> 
     <ColumnDefinition Width="3*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="3*"/> 
     <RowDefinition Height="2*"/> 
     <RowDefinition Height="3*"/> 
    </Grid.RowDefinitions> 
    <!-- Note that width and height are not set to make it size to the grid cell --> 
    <Button Grid.Row="1" Grid.Column="1" Content="Lorem Ipsum"/> 
    </Grid> 
</Window> 

(Vous pouvez essayer cela dans Kaxaml)


Si par le redimensionnement proportionnellement vous dire en fait la taille plutôt que l'espace de mise en page allouée puis utilisez un Viewbox.

+1

Eh bien oui, en fait le problème principal est quand, disons, l'utilisateur maximise la fenêtre et les boutons doivent redimensionner pour correspondre à l'échelle. Je suppose que je vais regarder ces colonnes et ces lignes. –

1

Tous les contrôles que vous souhaitez redimensionner (comme vos boutons) ils ne doivent pas avoir une largeur ou une hauteur définie dans votre XAML. Si elles ont besoin d'une taille minimum, utilisez MinWidth et MinHeight

+1

Je ne sais pas, ça n'a pas marché pour moi. Les contrôles n'étaient toujours pas redimensionnés. –

Questions connexes