views:

581

answers:

1

I have a user control which contains a StackPanel and TreeView. All controls have the Height="Auto" When I use the Cusotm control on a window and set Height, say Height=800 The STack Panel grows to this height, But the TreeView does not auto heigh adjust.

UserControl:

<UserControl x:Class="WPFDataBinding.ucCompanyTreeView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="200" Width="300" Loaded="UserControl_Loaded">
<StackPanel>
    <TextBlock Background="#505050" Foreground="Gold">Companys</TextBlock>
    <TreeView Name="myTreeView" ItemTemplate="{StaticResource DetailTemplate}">
    </TreeView>
</StackPanel>

Window1.xaml:

<StackPanel Orientation="Horizontal">
    <local:ucCompanyTreeView Width="400" Height="600">
    </local:ucCompanyTreeView>
</StackPanel>

The height of the stackpanel inside the usercontrol grows, but the Tree view does not. I have tried placing the tree view in a grid, same Setting Height="Auto" everywhere, same Setting VerticalAlignment="Strech" everywhere, same

The Treeview was data bound, so I thought it was auto sizing after the data was bound, but removing this data binding same results.

I can do it through sizing events.... but I have had this issue before and just want to understand the logic behind heigh inheritance of "some" controls.

Thanks

+1  A: 

If you were to replace the StackPanel in the User Control with a DockPanel, the TreeView would fill the DockPanel by default...

<DockPanel>
    <TextBlock DockPanel.Dock="Top" Background="#505050" Foreground="Gold">Companys</TextBlock>
    <TreeView Name="myTreeView" ItemTemplate="{StaticResource DetailTemplate}">
    </TreeView>
</DockPanel>

How to: Choose Between StackPanel and DockPanel

IanR