WPF: 拉伸树形视图

8

我刚开始接触WPF,需要一种方法来将TreeView控件拉伸到可用空间的全部大小。因此,水平和垂直拉伸是我的第一个猜测,但TreeView的行为就像“自动”大小一样...

我在这里做错了什么吗?

<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个回答

10

您已经将树包含在一个 StackPanel 中。移除 StackPanel 可能会得到您想要的结果。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接