问题描述
我想要一个可调整大小的扩展器之类的东西.我的基本想法是这样的:
I would like to have something like a resizable Expander. My basic idea was something like this:
<Grid HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="2" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Expander Grid.Column="0" ExpandDirection="Right">
...
</Expander>
<GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
...
</Grid>
这个问题:如果我移动网格分离器并折叠扩展器,我会得到一个很大的空白区域.怎样才能让整列倒塌?或者有没有另一种方法可以使扩展器可调整大小"
The problem with this: if i move the grid splitter and collaps the expander i got a big empty area. How can make the entire column collapse? Or is there another way to make the expander "resizable"
推荐答案
不确定您要完成什么,但我认为从概念上讲 Grid
应该是 Expander.Content,这对你有用吗?
Not sure what you are trying to accomplish but i think conceptually the Grid
should be part of the Expander.Content
, would this work for you?
<Expander Header="Test" ExpandDirection="Right" HorizontalAlignment="Left" Background="LightBlue">
<Expander.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="5"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Lorem ipsum dolor sit"/>
<GridSplitter Grid.Column="1" Width="5" ResizeBehavior="PreviousAndCurrent" ResizeDirection="Columns"/>
</Grid>
</Expander.Content>
</Expander>
删除了第一列中的所有触发,因为它似乎没有必要.
Removed all the triggering from the first column as it seemed unnecessary.
另外:为了垂直工作,GridSplitter 的 HorizontalAlignment
必须设置为 Stretch
,否则默认情况下它的宽度为零(当然其他所有特定于方向的东西也必须适应,但那是直截了当)
Also: For this to work vertically the GridSplitter's HorizontalAlignment
must be set to Stretch
, otherwise it will have zero width by default (of course everything else that is orientation-specific must be adapted as well but that is straightforward)
HorizontalAlignment 是 Microsoft .NET 属性访问器,它实际上是一个依赖属性.这个特定的依赖属性经常在子类元素(尤其是控件)中设置不同的明显默认"值.[...] 例如,即使 Label 直接从 FrameworkElement 继承 HorizontalAlignment,Label 控件的 HorizontalAlignment 的明显默认值"也将是 Left.这是因为该值已在 Label 的默认样式中重置,在样式的控件模板中.
这篇关于组合扩展器和网格(可调整大小的扩展器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!