WPF:Stretch treeview

时间:2011-05-05 15:23:08

标签: c# wpf treeview

我是WPF的新手,我需要一种方法将树视图控件拉伸到完整的可用尺寸..因此,水平和垂直拉伸是我的第一个猜测,但树视图的行为类似于“自动”大小...

我正在做某事。这里错了吗?

<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>

1 个答案:

答案 0 :(得分:9)

您已将树包裹在StackPanel中。删除StackPanel,你可能会得到你想要的东西。