如何“折叠组框可见性后覆盖空白”

时间:2019-09-04 11:13:41

标签: c# xaml

我正在编辑用户控件。该用户控件包含时间轴。我当前的问题是,当我在Groupbox上设置Visibility.Collapsed时,它消失了,这很好。但是,它后面有空白空间,我想要datagrid,它位于此groupbox下以具有完整大小并掩盖groupbox中的空白。

这是我得到的实际代码:

 <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="65"/>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>       
        <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="85" />
        </Grid.ColumnDefinitions>
        <GroupBox x:Name="gbLoadData" Style="{StaticResource GroupBoxStyle}" Grid.Column="0" Grid.Row="0" Visibility="{Binding Path=gbBasicInfoVisible, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Header="Základní informace" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="17*" />
                    <ColumnDefinition Width="85*" />
                    <ColumnDefinition Width="15*" />
                    <ColumnDefinition Width="70*" />
                </Grid.ColumnDefinitions>
                <Label Content="Řidič"  FontSize="16" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Height="30" />
                <Label Grid.Row="0"  FontSize="16" VerticalAlignment="Center" Content="SPZ" Grid.Column="2" Height="30" />
                <TextBox Margin="3" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" IsReadOnly="True" FontSize="16" Text="{Binding Driver,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="1"/>
                <TextBox Margin="3" HorizontalContentAlignment="Left" VerticalContentAlignment="Center"  IsReadOnly="True" FontSize="16" Text="{Binding SPZ,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="3" />
            </Grid>
        </GroupBox>           

        <GroupBox x:Name="gbdLoadData" Style="{StaticResource GroupBoxStyle}" Visibility="{Binding Path=gbExportVisible, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Header="Export" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" Grid.Column="1">
           <Button  x:Name="btnExportExcel"  Grid.Column="0" Command="{Binding ExportToExcelCmd}">
               <StackPanel>
                   <Image Source="/Z05.MES.WPF.WeighingSystem;Component/Resources/excel.png" Height="23" Width="32" />
               </StackPanel>
           </Button>
       </GroupBox>        
    </Grid>
    <DataGrid IsReadOnly="True" Grid.Row="1" Margin="5" Style="{StaticResource Z05DataGridStyle}" ItemsSource="{Binding CollectionTimeLineForRecord,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <DataGrid.Columns>
            <DataGridTextColumn x:Name="Popis"   MinWidth="150" FontSize="16"  Header="Popis" Width="10*"  Binding="{Binding ActionDescriptionText, UpdateSourceTrigger=PropertyChanged}" HeaderStyle="{StaticResource CenterGridHeaderStyle}">
                <DataGridTextColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="ToolTip" Value="{Binding ActionDescriptionText}"/>
                    </Style>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>
            <DataGridTextColumn x:Name="DateAndTime" FontSize="16" Width="150" MaxWidth="150" Header="Čas" Binding="{Binding DateTimeStamp, UpdateSourceTrigger=PropertyChanged, StringFormat=\{0:dd.MM.yy HH:mm:ss\}}" HeaderStyle="{StaticResource CenterGridHeaderStyle}" CellStyle="{StaticResource CellCenterStyle}"/>

            <DataGridTextColumn x:Name="Parametry" MinWidth="150" FontSize="16" Header="Parametry" Width="5*" Binding="{Binding ParametersFlat, UpdateSourceTrigger=PropertyChanged}"  HeaderStyle="{StaticResource CenterGridHeaderStyle}" >
                <DataGridTextColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="ToolTip" Value="{Binding ParametersFlat}"/>
                    </Style>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>

    <interactivity:InteractionTrigger SourceObject="{Binding NotificationRequest}" IsCentered="True" IsModal="True" Style="{StaticResource InteractionTrigger}">
    </interactivity:InteractionTrigger>

    <interactivity:InteractionTrigger  SourceObject="{Binding BoxWithMessageRequest}" IsCentered="True" IsModal="False" Style="{StaticResource InteractionTrigger}">
        <interactivity:InteractionTrigger.InteractionWindow>
            <boxMessage:DWBoxWithMessage/>
        </interactivity:InteractionTrigger.InteractionWindow>
    </interactivity:InteractionTrigger>

</Grid>

当我将组框设置为Visibility.Collapsed时,我只希望Datagrid变大。

1 个答案:

答案 0 :(得分:0)

尝试将“行和列”的HeigthWidth设置为auto而不是具体的值,例如:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>       
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
        ...
    </Grid>
    ...
</Grid>

然后,如果网格在行或列中无显示,则网格可以重新排列其内容。