我是 WPF 新手。我能够从这里找到如何制作可调整大小的垂直扩展器:Combine expander and grid (resizable expander)
所以我觉得做水平会很容易,我尝试了不同的方法都没有成功。
不用复杂的代码能搞定吗? 在 2 个网格行之间有一个 glidsplitter,其中一个有一个扩展器
布局看起来像这样:
左扩展器/gridsplitter 工作正常。但是底部的扩展器/网格分离器没有。不过,它在没有 gridsplitter 的情况下也能正常工作。
我的 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/