【问题标题】:Expander combined with GridSplitterExpander 结合 GridSplitter
【发布时间】:2016-11-18 11:34:36
【问题描述】:

我正在尝试将我的 WPF 窗口分成两个“区域”,顶部和底部。

  • 顶部区域包含一个网格。
  • 底部区域包含一个扩展器。

这两个区域之间应该是一个 GridSplitter,用户可以使用它来调整区域的大小。
每个区域的内容应该使用区域的全高。

默认情况下,扩展器是展开的。
当用户关闭扩展器时,底部区域的高度应降低到折叠扩展器的高度。

这是我的代码:

<Window
    x:Class="App.Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="Shell" Height="800" Width="1200">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid Name="MainContentGrid">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <!-- Top area -->
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Button Grid.Row="0" Grid.Column="0">1</Button>
                <Button Grid.Row="1" Grid.Column="0">2</Button>
                <Button Grid.Row="0" Grid.Column="1">3</Button>
                <Button Grid.Row="1" Grid.Column="1">4</Button>
            </Grid>
            <GridSplitter Grid.Row="1" 
              HorizontalAlignment="Stretch" 
              VerticalAlignment="Top"
              Background="Black" 
              ShowsPreview="true"
              ResizeDirection="Rows"
              Height="5"></GridSplitter>
            <!-- Bottom area -->
            <Expander Grid.Row="1" Margin="0,5,0,0" IsExpanded="True" Height="Auto" VerticalAlignment="Stretch">
                <Border Background="Red" Height="Auto" MinHeight="100" VerticalAlignment="Stretch"></Border>
            </Expander>
        </Grid>
        <!-- Application Status Region -->
        <ContentControl prism:RegionManager.RegionName="{x:Static local:RegionNames.StatusRegion}" Grid.Row="1" />
    </Grid>
</Window>

有两件事不起作用:

  • 扩展器没有全部可用空间(不改变其高度)

  • 当我关闭扩展器时,GridSplitter 不允许顶部区域使用所有可用空间。

我怎样才能做到这一点?

【问题讨论】:

    标签: c# wpf resize expander gridsplitter


    【解决方案1】:

    一旦您与GridSplitters 交互,他们就会在网格行/列定义上设置具体的相对或绝对Height/Width 值。因此,一旦折叠 Expander,您应该将其行的 Height 设置为 GridLength.Auto

    【讨论】:

    • 感谢您的帮助!您的解决方案有效。但我不得不改变另一件事...... GridSplitter 在它自己的行中......我删除了该行并将其添加到包含扩展器的行中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多