2009-07-16 4 views
1

Je suis nouveau sur WPF. J'ai une fenêtre WPF avec un tas d'étiquettes sur elle ainsi qu'un ListBox.WPF/XAML - Mise à l'échelle de la taille du texte à la taille de la fenêtre

Lors du redimensionnement de la fenêtre, je souhaite redimensionner la taille de QUELQUES Étiquettes, mais pas toutes. Je ne veux pas que le ListBox soit à l'échelle - juste quelques étiquettes. Je comprends que je peux utiliser une Viewbox pour redimensionner à mesure que la fenêtre se redimensionne, mais autant que je la dérange, je ne reçois pas l'effet désiré. Bien sûr, je ne peux pas entourer le tout avec une Viewbox, car cela redimensionnerait tout, donc je me suis dit que je devrais déposer un tas de différentes Viewboxes à travers la fenêtre entourant chaque étiquette que je veux développer. Mais bien sûr ... rien ne se développe quand je fais ça. Dans le même ordre d'idées, lorsque j'élargis les étiquettes, il y a d'autres étiquettes qui doivent rester à côté de ces étiquettes car ce sont des identifiants.

Alors ... voici le XAML que j'ai en ce moment. Je ne sais même pas si je suis sur le bon chemin. N'importe quelle aide faisant les étiquettes avec le nombre dans eux se développerait avec la fenêtre serait appréciée.

<Window x:Class="WpfApplication7.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:WpfApplication7" 
    Title="Window1"> 
    <StackPanel Orientation="Horizontal"> 
     <ListBox Margin="2"> 
      <ListBoxItem>a</ListBoxItem> 
      <ListBoxItem>b</ListBoxItem> 
      <ListBoxItem>c</ListBoxItem> 
     </ListBox> 
     <StackPanel Orientation="Vertical"> 
      <Label>Title</Label> 
      <StackPanel Orientation="Horizontal"> 
       <Grid> 
        <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions> 
        <Label Grid.Row="0">A</Label> 
        <Label Grid.Row="1">B</Label> 
        <Label Grid.Row="2">C</Label> 
        <Label Grid.Row="3">D</Label> 
       </Grid> 
       <Grid> 
        <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions> 
        <Viewbox Grid.Row="0" Stretch="Fill"> 
         <Label>1</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="1" Stretch="Fill"> 
         <Label>2</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="2" Stretch="Fill"> 
         <Label>3</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="3" Stretch="Fill"> 
         <Label>4</Label> 
        </Viewbox> 
       </Grid> 
       <Grid> 
        <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions> 
        <Viewbox Grid.Row="0" Stretch="Fill"> 
         <Label>5</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="1" Stretch="Fill"> 
         <Label>6</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="2" Stretch="Fill"> 
         <Label>7</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="3" Stretch="Fill"> 
         <Label>8</Label> 
        </Viewbox> 
       </Grid> 
       <Grid> 
        <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions> 
        <Label Grid.Row="0">E</Label> 
        <Label Grid.Row="1">F</Label> 
        <Label Grid.Row="2">G</Label> 
        <Label Grid.Row="3">H</Label> 
       </Grid> 
      </StackPanel> 
     </StackPanel> 
    </StackPanel> 
</Window> 

+0

mon travail Avez-fix pour vous? Vous n'avez pas encore choisi de réponse. – Charlie

Répondre

2

Vous êtes sur le bon chemin. Cependant, vous devez utiliser certaines définitions de colonnes et vos définitions de lignes sont un peu bancales. Vous utilisez un ensemble de panneaux de disposition différents, ce qui affecte le redimensionnement intégré de Viewbox. Vous pouvez accomplir exactement la même mise en page avec une seule grille simple de 5x5 (pas de panneaux de pile).

J'ai démontré dans le XAML suivant:

<Window x:Class="TestWpfApplication.Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="clr-namespace:TestWpfApplication" 
Title="Window1"> 
<Window.Resources> 
    <Style TargetType="{x:Type Label}" x:Key="{x:Type Label}"> 
     <Setter Property="HorizontalAlignment" Value="Center"/> 
     <Setter Property="VerticalAlignment" Value="Center"/> 
    </Style> 
</Window.Resources> 

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition/> 
     <RowDefinition/> 
     <RowDefinition/> 
     <RowDefinition/> 
     <RowDefinition/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
    </Grid.ColumnDefinitions> 

    <ListBox Grid.RowSpan="5" Grid.Column="0"> 
     <ListBoxItem>a</ListBoxItem> 
     <ListBoxItem>b</ListBoxItem> 
     <ListBoxItem>c</ListBoxItem> 
    </ListBox> 

    <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4">Title</Label> 

    <Label Grid.Row="1" Grid.Column="1">A</Label> 
    <Label Grid.Row="2" Grid.Column="1">B</Label> 
    <Label Grid.Row="3" Grid.Column="1">C</Label> 
    <Label Grid.Row="4" Grid.Column="1">D</Label> 

    <Viewbox Grid.Row="1" Grid.Column="2"> 
     <Label>1</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="2" Grid.Column="2"> 
     <Label>2</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="3" Grid.Column="2"> 
     <Label>3</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="4" Grid.Column="2"> 
     <Label>4</Label> 
    </Viewbox> 

    <Viewbox Grid.Row="1" Grid.Column="3"> 
     <Label>5</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="2" Grid.Column="3"> 
     <Label>6</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="3" Grid.Column="3"> 
     <Label>7</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="4" Grid.Column="3"> 
     <Label>8</Label> 
    </Viewbox> 

    <Label Grid.Row="1" Grid.Column="4">E</Label> 
    <Label Grid.Row="2" Grid.Column="4">F</Label> 
    <Label Grid.Row="3" Grid.Column="4">G</Label> 
    <Label Grid.Row="4" Grid.Column="4">H</Label> 
</Grid> 

Questions connexes