2009-09-27 6 views
9

Existe-t-il un moyen de combiner des lignes dans une colonne spécifique? Par conséquent, pour obtenir quelque chose comme ça (je suis actuellement en utilisant rowspan sur un contrôle-à-dire l'image, mais est-il une meilleure façon?)WPF: comment combiner des lignes dans une colonne (alternative à rowspan)?

-------------------- 
    |   |--------| 
    |   |--------| 
    |   |--------| 
    |   |--------| 
    |   |--------| 
    -------------------- 

J'utilise ce code essentiellement

<Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="28" /> 
     <RowDefinition Height="28" /> 
     <RowDefinition Height="28" /> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="28" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="124" /> 
     <ColumnDefinition Width="246*" /> 
    </Grid.ColumnDefinitions> 

Ce qui me donne quelque chose comme ce (notez les lignes apparaissent également dans la colonne 0)

-------------------- 
    |---------|--------| 
    |---------|--------| 
    |---------|--------| 
    |---------|--------| 
    |---------|--------| 
    -------------------- 

maintenant, je peux contourner ce par exemple, si je veux placer une image que je peux utiliser RowSpan, mais est-il pas possible de concevoir une colonne w sans lignes et les autres colonnes ayant des lignes?

Répondre

11

Cela n'est pas possible avec le contrôle Grid. Les lignes traversent toutes les colonnes et les colonnes traversent toutes les lignes. Comme vous l'avez constaté, les codes RowSpan et ColumnSpan vous permettent d'avoir un contrôle sur plusieurs lignes ou colonnes respectivement.

Une autre solution potentielle est d'accueillir un Grid dans une autre:

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*"/> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 

    <Image/> 

    <Grid Grid.Column="1"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 
    </Grid> 
</Grid> 
+0

Merci, mais je suppose que le code supplémentaire ne vaut pas le coup? .. Je présume qu'il vaut mieux continuer à utiliser ma grille et juste utiliser RowSpan etc? –

+0

@Mark: oui, à en juger par votre description, je dirais que RowSpan est le moyen le plus facile d'atteindre votre objectif. –

1

Que diriez-vous quelque chose comme ceci:

  <StackPanel Orientation="Horizontal"> 
       <Grid Height="100" Width="50"></Grid> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="*" /> 
         <RowDefinition Height="*" /> 
         <RowDefinition Height="*" /> 
         <RowDefinition Height="*" /> 
         <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="150" /> 
        </Grid.ColumnDefinitions> 
       </Grid> 
      </StackPanel> 
0

essayez d'utiliser rectangle pour fusionner les 6 lignes.

<Grid> 
<Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="28" /> 
    <RowDefinition Height="28" /> 
    <RowDefinition Height="28" /> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="28" /> 
</Grid.RowDefinitions> 
<Grid.ColumnDefinitions> 
    <ColumnDefinition Width="124" /> 
    <ColumnDefinition Width="246*" /> 
</Grid.ColumnDefinitions> 
<Rectangle Grid.RowSpan="6"/> 
</Grid> 
Questions connexes