2013-07-14 3 views
3

Je suis nouveau sur WPF. J'ai été capable de trouver comment faire un expandeur vertical redimensionnable à partir d'ici: Combine expander and grid (resizable expander)wpf est-il possible d'avoir un expandeur horizontal redimensionnable?

Alors j'ai pensé que faire un horizontal serait facile, j'ai essayé différentes façons sans succès.

Peut-il être fait sans code complexe? Pour avoir une glidsplitter entre 2 rangées de la grille dont l'un d'entre eux a un dispositif d'expansion


La mise en page ressemble à ceci:

Expander gauche/GridSplitter fonctionne très bien. Mais l'expander/gridsplitter au fond n'a pas. Cela fonctionne bien sans un séparateur de grille.

enter image description here

Mon XAML:

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="10" /> 
     <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 

    <DockPanel Grid.Row="0"> 
     <Expander ExpandDirection="Left" Header=""> 
      <Expander.Content> 
       <Grid> 
        <!-- this works --> 
       </Grid> 
      </Expander.Content> 
     </Expander> 
     <TextBox AcceptsReturn="True" /> 
    </DockPanel> 

    <GridSplitter Grid.Row="1" Height="10" HorizontalAlignment="Stretch" ResizeBehavior="PreviousAndCurrent" ResizeDirection="Rows"/> 

    <DockPanel Grid.Row="2"> 
     <Expander ExpandDirection="Down" Header="Summary"> 
      <Expander.Content> 
       <TextBox AcceptsReturn="True" /> 
      </Expander.Content> 
     </Expander> 
    </DockPanel> 
</Grid> 

Si vous supprimez la ligne médiane et la GridSplitter, il fonctionne très bien, mais ce n'est pas redimensionnable.

Toute aide est appréciée.

+0

Comment pouvez-vous attendre à un séparateur pour effectuer la hauteur fixe en bas? – Paparazzi

+0

@Blam ce n'est pas le problème. Un expandeur horizontal redimensionnable (c'est-à-dire en bas). Une autre question mais pas résolue: http://stackoverflow.com/questions/15976057/allow-users-to-resize-expander-in-wpf – OsakaHQ

+0

@Blam Je l'ai effacé car ce n'est pas le problème. J'ai essayé plusieurs façons. Je pense que l'expandeur n'a pas été conçu à des fins de redimensionnement. – OsakaHQ

Répondre

2

La hauteur de la 3ème rangée doit également être proportionnelle. Spécifiez MinHeight pour les première et dernière lignes afin qu'elles ne rétrécissent pas complètement.

Modifié XAML:

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="6*" MinHeight="100"/> 
     <RowDefinition Height="10" /> 
     <RowDefinition Height="*" MinHeight="50"/> 
    </Grid.RowDefinitions> 

    <DockPanel Grid.Row="0"> 
     <Expander ExpandDirection="Left" Header=""> 
      <Expander.Content> 
       <Grid> 
        <!-- this works --> 
       </Grid> 
      </Expander.Content> 
     </Expander> 
     <TextBox AcceptsReturn="True" /> 
    </DockPanel> 

    <GridSplitter Grid.Row="1" Height="2" HorizontalAlignment="Stretch"/> 

    <DockPanel Grid.Row="2"> 
     <Expander ExpandDirection="Down" Header="Summary"> 
      <Expander.Content> 
       <TextBox AcceptsReturn="True" /> 
      </Expander.Content> 
     </Expander> 
    </DockPanel> 
</Grid> 
+0

Merci pour votre contribution. Mais peut-être que je demande quelque chose que cela ne peut pas être fait? L'Expander ne fonctionne pas comme le vertical. – OsakaHQ

2

Les œuvres suivantes pour moi. Le GridSplitter est affiché lorsqu'il est développé et masqué lorsqu'il est réduit.

J'utilise des ellipses qui remplissent les volets dans l'exemple, car cela permet de voir facilement l'espace occupé par chaque panneau.

Xaml

<Grid Background="Green"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="Auto" Name="expanderRow"/> 
    </Grid.RowDefinitions> 
    <Ellipse Grid.Row="0" Fill="Black"></Ellipse> 
    <Expander Grid.Row="2" ExpandDirection="Up" IsExpanded="False" Background="Yellow" 
       Expanded="Expander_Expanded" 
       Collapsed="Expander_Collapsed"> 
     <Ellipse Fill="Red"/> 
    </Expander> 
    <GridSplitter Grid.Row="1" Height="15" HorizontalAlignment="Stretch" Name="expander" Visibility="Collapsed"></GridSplitter> 
</Grid> 

code derrière

private GridLength expandedHeight = new GridLength(0.5, GridUnitType.Star); 

    public MainWindow() 
    { 
     InitializeComponent(); 
    } 

    private void Expander_Expanded(object sender, RoutedEventArgs e) 
    { 
     expanderRow.Height = expandedHeight; 
     expander.Visibility = Visibility.Visible; 
    } 

    private void Expander_Collapsed(object sender, RoutedEventArgs e) 
    { 
     expandedHeight = expanderRow.Height; 
     expanderRow.Height = GridLength.Auto; 
     expander.Visibility = Visibility.Collapsed; 
    } 
Questions connexes