Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Stretch treeview

Tags:

c#

wpf

treeview

i am new to WPF and i need a way to stretch a treeview control to the full available size.. so, horizontal and vertical stretching was my first guess, but the treeview behaves like "Auto" sized...

am i doing sth. wrong here?

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="WpfApplication2.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="500" Height="500"
MinWidth="500" MinHeight="500">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>  
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <StackPanel Grid.Row="0" Orientation="Vertical">
        <TreeView VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <TreeViewItem>asdasd</TreeViewItem>
            <TreeViewItem>asdasd</TreeViewItem>
        </TreeView>
    </StackPanel>
    <Label Grid.Row="1">asdasd</Label>
</Grid>
</Window>
like image 615
David Avatar asked May 05 '11 15:05

David


1 Answers

You have wrapped your tree in a StackPanel. Remove the StackPanel and you probably will get what you're looking for.

like image 163
HCL Avatar answered Oct 15 '22 23:10

HCL