2013-09-03 12 views
6

My expanding menuWPF come rendere i contenuti di espansione mossa

Salve vorrei aggiungere controllo WPF per ElementHost nella mia applicazione WinForms. Il comportamento del mio controllo è raffigurato sull'immagine. Desidero espandere qualsiasi espansione per ridimensionare il controllo del controllo ad albero a dimensioni ridotte. E all'inizio vorrei che i miei expander fossero crollati.

Stavo cercando sth così:

<UserControl x:Class="LeftPane" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     mc:Ignorable="d" > 
<Grid VerticalAlignment="Stretch" Margin="3,3,3,3"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/>    
    </Grid.RowDefinitions> 
    <TreeView Grid.Row="0" Name="treeView1" VerticalAlignment="Stretch" > 

    </TreeView> 
    <StackPanel Grid.Row="1" Name="StackPanel1" VerticalAlignment="Bottom"> 
     <ListBox SelectedIndex="1"> 
      <ListBoxItem VerticalAlignment="Stretch"> 
       <Expander Grid.Row="1" ExpandDirection="Down" Header="expander1" VerticalAlignment="Stretch" Name="expander1" IsExpanded="False"> 
        <ListBox> 
         <ListBoxItem Content="Unit 1"/> 
         <ListBoxItem Content="Unit 2"/> 
        </ListBox> 
       </Expander> 
      </ListBoxItem> 
      <ListBoxItem VerticalAlignment="Stretch"> 
       <Expander Grid.Row="2" ExpandDirection="Down" Header="expander2" VerticalAlignment="Stretch" Name="expander2" IsExpanded="False"> 
        <ListBox> 
         <ListBoxItem Content="Unit 1"/> 
         <ListBoxItem Content="Unit 2"/> 
        </ListBox> 
       </Expander> 
      </ListBoxItem> 
     </ListBox> 
    </StackPanel> 
</Grid> 

e:

public void AddControl(ElementHost host) 
    { 
     this.parentHost = host; 
     host.Child = this; 
     this.Height = host.Size.Height; 
     treeView1.MaxHeight = this.Height - 60; 

    } 

Ma non funziona correttamente. Vorrei inoltre ridimensionare questo controllo mentre ridimensiono la finestra winForms.

qualcuno mi può aiutare come impostare Aligment ecc

risposta

5

Questo è come vorrei realizzare questo ... prima, vorrei cambiare il Grid al seguente:

<Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="Auto" /> 
    <RowDefinition Height="Auto" /> 
</Grid.RowDefinitions> 

Ciò fornirà la due Expander controlli con quanto più spazio di cui hanno bisogno e il TreeView con tutto il resto:

<TreeView Grid.Row="0" Name="treeView1" /> 
<Expander Grid.Row="1" Header="expander1" Name="expander1" IsExpanded="False"> 
    <ListBox> 
     <ListBoxItem Content="Unit 1"/> 
     <ListBoxItem Content="Unit 2"/> 
    </ListBox> 
</Expander> 
<Expander Grid.Row="2" Header="expander2" Name="expander2" IsExpanded="False"> 
    <ListBox> 
     <ListBoxItem Content="Unit 1"/> 
     <ListBoxItem Content="Unit 2"/> 
    </ListBox> 
</Expander> 
+1

Fa apparire un espansore su un altro. Inoltre, il controllo non viene ridimensionato quando ridimensiono la finestra dei genitori WinForms. – santBart

+0

@santBart supponiamo che Sheridan intendesse Grid.Row = "2" sul secondo expander – Alex

+0

Grazie a @voo. Scusa, errore mio ... Ho aggiornato il mio codice ora. – Sheridan

0

per rendere il mio controllo ridimensionabile, Ho cambiato la proprietà ElementHost Dock to Fill.

Problemi correlati