tags:

views:

12

answers:

1

I would like the TreeView below to expand to fill the current row that it is contained within, however, I can't figure out how this is done. It just expands to fit the tree items. Can this be done, and if so, how?

Thanks

<Window x:Class="WorkoutUI.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Name="Window" Height="350" Width="525">
    <Grid Name="Root_Grid">
        <Grid.RowDefinitions>
            <RowDefinition Height="10" />
            <RowDefinition Height="*" Name="Root_Grid_Row_2" />
            <RowDefinition Height="10" />            
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="5" />
        </Grid.ColumnDefinitions>

        <TreeView Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" VerticalContentAlignment="Stretch" Width="{Binding Width, ElementName=Root_Grid, Mode=Default}">
            <TreeViewItem Header="Workouts" IsExpanded="True">
                <TreeViewItem Header="Workout1" />
                <TreeViewItem Header="Workout2" />
                <TreeViewItem Header="Workout3" IsExpanded="True">
                    <TreeViewItem Header="WorkoutSub1" />
                    <TreeViewItem Header="WorkoutSub2" />
                    <TreeViewItem Header="WorkoutSub3" />
                </TreeViewItem>    
                <TreeViewItem Header="Workout4" />
                <TreeViewItem Header="Workout5" />
                <TreeViewItem Header="Workout6" />                
            </TreeViewItem>            
        </TreeView>
    </Grid>
</Window>
A: 

You have VerticalAlignment="Top", which means the TreeView will only be as tall as it wants to be and will be placed in the top of the available space. You want to set the VerticalAlignment to Stretch so that it will take up all available vertical space. Since this is the default, you can just remove the attribute:

<TreeView Grid.Column="1" Grid.Row="1" Width="{Binding Width, ElementName=Root_Grid, Mode=Default}">
Quartermeister