1
我在使用一个网格,一个WPF应用程序的工作涉及的电力网一对夫妇的TreeView里面:树形内网和比例大小
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Header"/>
<TreeView x:Name="Tree1"" Grid.Row="2"/>
<TextBlock Text="SecondHeader" Grid.Row="2"/>
<TreeView x:Name="Tree2" Grid.Row="3"/>
</Grid>
采用这种设置,标题将有大小成正比网格的大小。
问题发生在我有一棵较小的树时,并且两棵树之间有一个空白区域,并且如果第一棵树是空的,它也将占据网格的一半。
如果我更改代码这样:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Header"/>
<TreeView x:Name="Tree1"" Grid.Row="2"/>
<TextBlock Text="SecondHeader" Grid.Row="2"/>
<TreeView x:Name="Tree2" Grid.Row="3"/>
</Grid>
我得到一个非常相似的结果我想要的东西,但在这种情况下,树木的滚动条会显示不出来,因为树木会占用所有他们需要的地方,它会溢出我的网格。
如果我奉上的ScrollViewer内的第二个方案,我会得到整个电网的共同滚动:
<ScrollViewer><Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Header"/>
<TreeView x:Name="Tree1"" Grid.Row="2"/>
<TextBlock Text="SecondHeader" Grid.Row="2"/>
<TreeView x:Name="Tree2" Grid.Row="3"/>
</Grid></ScrollViewer>
这种解决方案的问题是:如果第一个树是足够长的时间,在用户中赢得除非他向下滚动,否则不会看到第二棵树,并且要求两棵树始终可见。
恢复我需要具有以下功能的设置:
- 显示网格内的两个树视图
- 这些树视图必须有自己的滚动
- 如果树视图中的一个没有任何元素,该不该没有差距。
任何想法?