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>
這種解決方案的問題是:如果第一個樹是足夠長的時間,在用戶中贏得除非他向下滾動,否則不會看到第二棵樹,並且要求兩棵樹始終可見。
恢復我需要具有以下功能的設置:
- 顯示網格內的兩個樹視圖
- 這些樹視圖必須有自己的滾動
- 如果樹視圖中的一個沒有任何元素,該不該沒有差距。
任何想法?