如何在用户展开/折叠树视图时保持区域恒定/相对大小? [英] How to keep an area a constant/relative size while user expands/collapses treeview?
问题描述
我有一个可变大小的窗口,目前为 300 x 400,如下所示.
I have a window that will be a variable size, currently it is 300 x 400 as shown below.
在顶部部分,我有一个可扩展的树视图在底部部分,我有一个长长的水平面板,里面有一个按钮.
In the top part I have an expandable tree view In the bottom part I have a long horizontal panel with a button in it.
我希望顶部区域(树状视图)大约为高度的 95%,按钮工具区域的高度为 50.
I want the top area (treeview) to be about 95% of the height, with the button tool area a constant 50 high.
我希望这些比例在用户展开和折叠树视图时保持恒定(并且当它在按钮工具栏下方展开时,我希望视图滚动条弹出一个滚动条.
I want these proportions to stay constant as the user expands and collapses the tree view (and as it expands below the button toolbar, I want the viewscroller to pop in with a scrollbar.
我该怎么做?这是迄今为止我能做的最好的事情,但是当用户折叠树视图时按钮区域会向上移动.:
How can I do this? Here's the best I could do so far, but the button area moves up as the user collapses the tree view. :
<Window x:Class="TestSize8383.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="400">
<Window.Resources>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True" />
</Style>
</Window.Resources>
<DockPanel Background="Beige" Margin="3" LastChildFill="False">
<ScrollViewer DockPanel.Dock="Top" Background="White" Margin="3">
<TreeViewItem DockPanel.Dock="Top" Background="White" Header="Page 1" IsExpanded="True">
<TreeViewItem Header="Part 1">
<TreeViewItem Header="Paragraph 1">
<TreeViewItem Header="Word 1"/>
<TreeViewItem Header="Word 2"/>
</TreeViewItem>
<TreeViewItem Header="Paragraph 2">
<TreeViewItem Header="Word 1"/>
<TreeViewItem Header="Word 2"/>
</TreeViewItem>
<TreeViewItem Header="Paragraph 3">
<TreeViewItem Header="Word 1"/>
<TreeViewItem Header="Word 2"/>
</TreeViewItem>
<TreeViewItem Header="Part 2">
<TreeViewItem Header="Paragraph 1">
<TreeViewItem Header="Word 1"/>
<TreeViewItem Header="Word 2"/>
</TreeViewItem>
<TreeViewItem Header="Paragraph 2">
<TreeViewItem Header="Word 1"/>
<TreeViewItem Header="Word 2"/>
</TreeViewItem>
<TreeViewItem Header="Paragraph 3">
<TreeViewItem Header="Word 1"/>
<TreeViewItem Header="Word 2"/>
</TreeViewItem>
</TreeViewItem>
</TreeViewItem>
</TreeViewItem>
</ScrollViewer>
<StackPanel DockPanel.Dock="Bottom" Background="Tan" Margin="3" Height="50">
<Button Content="Previous" Margin="5"/>
</StackPanel>
</DockPanel>
</Window>
推荐答案
使用 Grid 而不是 DockPanel 怎么样?
How about using a Grid instead of using a DockPanel?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0">
...
</ScrollViewer>
<StackPanel Grid.Row="1">
...
</StackPanel>
</Grid>
这篇关于如何在用户展开/折叠树视图时保持区域恒定/相对大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!