我是 WPF 的新手,我需要一种方法将 TreeView 控件拉伸(stretch)到完整的可用大小。所以,水平和垂直拉伸(stretch)是我的第一个猜测,但 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>
最佳答案
您已将您的树包裹在 StackPanel
中。删除 StackPanel
,您可能会得到想要的东西。
关于c# - WPF:拉伸(stretch) TreeView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5900248/