我希望下面的TreeView能够扩展以填充它所包含的当前行,但是,我无法弄清楚这是如何完成的。它只是扩展以适应树项。可以这样做,如果是这样,怎么办?
由于
<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>
答案 0 :(得分:2)
你有VerticalAlignment="Top"
,这意味着TreeView只会像它想要的那样高,并且会被放置在可用空间的顶部。您希望将VerticalAlignment设置为Stretch,以便占用所有可用的垂直空间。由于这是默认设置,因此您只需删除属性:
<TreeView Grid.Column="1" Grid.Row="1" Width="{Binding Width, ElementName=Root_Grid, Mode=Default}">