网格覆盖了另一个关于WPF中的大小调整

时间:2014-10-09 15:37:53

标签: c# wpf

GroupBox我有两个网格:第一个包含可以包含许多文本框,因此我添加了ScrollViewer,第二个包含必须始终可见的操作按钮。 上面的第二个GroupBox有一个Expander,问题是当它展开并且第一个网格有足够的元素时,它会用按钮覆盖第二个网格。我该如何解决这个问题?

这是我的代码:

<Window x:Class="ControlOverlayBug.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="269" Width="454">
<DockPanel Background="LightGray" SnapsToDevicePixels="True">
    <GroupBox DockPanel.Dock="Top" Header="Simulation Parameters">
        <DockPanel>
            <Expander DockPanel.Dock="Bottom" x:Name="AlgoParams" Header="Change Us...">
                <Grid x:Name="parameterGrid">
                    <DataGrid
                            RowHeaderWidth="0"
                            ItemsSource="{Binding AlgoParameters}" 
                            AutoGenerateColumns="False"
                            GridLinesVisibility="None"
                            CanUserAddRows="False" 
                            CanUserDeleteRows="False" 
                            CanUserReorderColumns="False">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Name" Binding="{Binding Name}"  Width="1*" IsReadOnly="True"/>
                            <DataGridTextColumn Header="Description" Binding="{Binding Description}"  Width="1*"/>
                            <DataGridTextColumn Header="Value" Binding="{Binding Value}"  Width="1*"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </Expander>
        </DockPanel>
    </GroupBox>

    <GroupBox DockPanel.Dock="Bottom" Header="Other Parameters">
        <DockPanel x:Name="BindPanel" VerticalAlignment="Stretch">
            <ScrollViewer VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top" >
                <Grid x:Name="paramGrid"  Margin="3" Background="Yellow">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30"/>
                        <ColumnDefinition Width="200*"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="363*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <GridSplitter Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ResizeDirection="Columns" Width="5" Height="Auto" ShowsPreview="false"/>
                    <Label Content="ID" FontWeight="Bold" HorizontalAlignment="Center"/>
                    <Label Content="Name" Grid.Column="1" FontWeight="Bold" HorizontalAlignment="Left"/>
                    <Label Content="Values" Grid.Column="3" FontWeight="Bold" HorizontalAlignment="Left"/>

                    <TextBlock Grid.Row="1" Text="1"/>
                    <TextBlock Grid.Row="1" Grid.Column="1" Text="p10"/>
                    <TextBlock Grid.Row="1" Grid.Column="4" Text="bla"/>

                    <TextBlock Grid.Row="2" Text="2"/>
                    <TextBlock Grid.Row="2" Grid.Column="1" Text="p11"/>
                    <TextBlock Grid.Row="2" Grid.Column="4" Text="blub"/>
                </Grid>
            </ScrollViewer>

            <Grid DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Background="AliceBlue" MinHeight="30">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="123"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button Content="_Load Settings" HorizontalAlignment="Left"/>
                <Button Content="_Save Settings" Grid.Column="1" HorizontalAlignment="Left"/>
                <Button Content="_Run Simulation" Grid.Column="2" HorizontalAlignment="Right"/>
            </Grid>
        </DockPanel>
    </GroupBox>
</DockPanel>

提前致谢!

2 个答案:

答案 0 :(得分:0)

为ScrollViewer添加MaxHeight以使滚动工作而不是重叠

答案 1 :(得分:0)

好吧,我通过将DockPanel(名为BindPanel)更改为Grid两行(第二行具有固定高度)来解决问题,并且它可以正常工作。这里有趣的部分:

 <GroupBox DockPanel.Dock="Bottom" Header="Other Parameters">
        <Grid x:Name="BindPanel" VerticalAlignment="Stretch" Background="Beige">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="24"/>
            </Grid.RowDefinitions>
            <ScrollViewer VerticalScrollBarVisibility="Auto" VerticalAlignment="Top">
                ...
            </ScrollViewer>

            <!-- grid wih buttons -->
        </Grid>
  </GroupBox>