gpt4 book ai didi

c# - wpf 是否可以有一个可调整大小的水平扩展器?

转载 作者:太空狗 更新时间:2023-10-30 00:53:09 26 4
gpt4 key购买 nike

我是 WPF 新手。我能够从这里找到如何制作可调整大小的垂直扩展器:Combine expander and grid (resizable expander)

所以我觉得做水平会很容易,我尝试了不同的方法都没有成功。

不用复杂的代码能搞定吗? 在 2 个网格行之间有一个 glidsplitter,其中一个有一个扩展器


布局看起来像这样:

左扩展器/gridsplitter 工作正常。但是底部的扩展器/网格分离器没有。不过,它在没有 gridsplitter 的情况下也能正常工作。

enter image description here

我的 XAML:

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<DockPanel Grid.Row="0">
<Expander ExpandDirection="Left" Header="">
<Expander.Content>
<Grid>
<!-- this works -->
</Grid>
</Expander.Content>
</Expander>
<TextBox AcceptsReturn="True" />
</DockPanel>

<GridSplitter Grid.Row="1" Height="10" HorizontalAlignment="Stretch" ResizeBehavior="PreviousAndCurrent" ResizeDirection="Rows"/>

<DockPanel Grid.Row="2">
<Expander ExpandDirection="Down" Header="Summary">
<Expander.Content>
<TextBox AcceptsReturn="True" />
</Expander.Content>
</Expander>
</DockPanel>
</Grid>

如果您删除中间行和网格拆分器,它可以正常工作,但无法调整大小。

感谢任何帮助。

最佳答案

第三行的高度也应该成比例。为第一行和最后一行指定 MinHeight,这样它们就不会完全收缩。

编辑的 XAML:

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="6*" MinHeight="100"/>
<RowDefinition Height="10" />
<RowDefinition Height="*" MinHeight="50"/>
</Grid.RowDefinitions>

<DockPanel Grid.Row="0">
<Expander ExpandDirection="Left" Header="">
<Expander.Content>
<Grid>
<!-- this works -->
</Grid>
</Expander.Content>
</Expander>
<TextBox AcceptsReturn="True" />
</DockPanel>

<GridSplitter Grid.Row="1" Height="2" HorizontalAlignment="Stretch"/>

<DockPanel Grid.Row="2">
<Expander ExpandDirection="Down" Header="Summary">
<Expander.Content>
<TextBox AcceptsReturn="True" />
</Expander.Content>
</Expander>
</DockPanel>
</Grid>

关于c# - wpf 是否可以有一个可调整大小的水平扩展器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17635718/

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