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

标签 c# wpf visual-studio-2010 xaml

我是 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/

相关文章:

c# - AutoMapper 具有来自 IDataReader 的列表数据

c# - 如何在 C# 中以编程方式关闭 InfoPath 表单?

c# - 使用 SSL 的 .net Web 服务。 wcf?

c# - 更改边距背景颜色

c++ - fatal error LNK1158 : cannot run 'mt.exe'

visual-studio-2010 - VS2010 打开文件时打不开解决办法

c# - Excel ExcelDNA C#/尝试复制 Bloomberg BDH() 行为(在网络请求后写入数组)

c# - 如何检查窗口是否已经打开?重复窗口

wpf - 本地 WPF C# 编程

wpf - 如何在运行时在 WPF 中加载外部字体文件