gpt4 book ai didi

wpf - 组合扩展器和网格(可调整大小的扩展器)

转载 作者:行者123 更新时间:2023-12-03 20:24:08 24 4
gpt4 key购买 nike

我想要一个可调整大小的扩展器。我的基本想法是这样的:

<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>

问题在于:如果我移动网格分离器并折叠扩展器,我会得到一个很大的空白区域。怎样才能让整列折叠?或者还有另一种方法可以使扩展器“调整大小”

最佳答案

不确定您要完成什么,但我认为从概念上讲 Grid应该是 Expander.Content 的一部分,这对你有用吗?

<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>

编辑:从第一列中删除了所有触发,因为它似乎没有必要。

另外:为了垂直工作,GridSplitter 的 HorizontalAlignment 必须设置为 Stretch , 否则默认情况下它将具有零宽度(当然其他所有特定于方向的内容也必须进行调整,但这很简单)

HorizontalAlignment is the Microsoft .NET property accessor for what is in reality a dependency property. This particular dependency property quite frequently has its apparent "default" value set differently in subclassed elements, particularly controls. [...] For example, the apparent "default" of HorizontalAlignment for a Label control will be Left, even though Label inherits HorizontalAlignment direct from FrameworkElement. This is because that value was reset within the default style of Label, within the style's control template.

关于wpf - 组合扩展器和网格(可调整大小的扩展器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5553383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com