简体   繁体   English

扩展器与GridSplitter结合使用

[英]Expander combined with GridSplitter

I'm trying to split my WPF window into two “areas”, top and bottom. 我正在尝试将我的WPF窗口分成两个“区域”,顶部和底部。

  • The top area contains a grid. 顶部区域包含一个网格。
  • The bottom area contains an expander. 底部区域包含一个扩展器。

Between the two areas should be a GridSplitter which the user can use to resize the areas. 两个区域之间应该是GridSplitter,用户可以使用它来调整区域大小。
The content of each area should use the full high of the area. 每个区域的内容应使用该区域的全高。

预期

By default, the expander is expanded. 默认情况下,展开器会展开。
When the user closes the expander, the bottom area should reduce its height to the height of the collapsed expander. 当用户关闭扩展器时,底部区域应将其高度降低到折叠扩展器的高度。

This is my code: 这是我的代码:

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

Two things are not working: 有两件事没有用:

  • The expander does not all available space (does not change its height) 扩展器并非所有可用空间(不改变其高度) 扩展器没有使用所有可用空间

  • When I close the expander, the GridSplitter does not allow the top area to use all the space available. 当我关闭扩展器时,GridSplitter不允许顶部区域使用所有可用空间。 顶部区域不使用所有可用空间

How can I make this work? 我怎样才能做到这一点?

Once you interact with GridSplitters they set concrete relative or absolute Height / Width values on the grid row/column definitions. GridSplitters交互后,他们在网格行/列定义上设置具体的相对或绝对Height / Width值。 So once you collapse the Expander you should set its row's Height to GridLength.Auto . 所以一旦你崩溃Expander你应该将它的行Height设置为GridLength.Auto

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM