Hide grid row in WPF

前端 未结 8 1448
旧巷少年郎
旧巷少年郎 2020-12-02 15:21

I have a simple WPF form with a Grid declared on the form. This Grid has a bunch of rows:


    

        
相关标签:
8条回答
  • 2020-12-02 15:46

    The best and clean solution to collapse rows or columns is to use a DataTrigger so in your case:

    <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" MinHeight="30" />
          <RowDefinition Name="rowToHide">
            <RowDefinition.Style>
              <Style TargetType="{x:Type RowDefinition}">
                <Setter Property="Height" Value="Auto" />
                <Style.Triggers>
                  <DataTrigger Binding="{Binding SomeBoolProperty}" Value="True">
                    <Setter Property="Height" Value="0" />
                  </DataTrigger>
                </Style.Triggers>
              </Style>
            </RowDefinition.Style>
          </RowDefinition>
          <RowDefinition Height="Auto" MinHeight="30" />
        </Grid.RowDefinitions>
      </Grid>
    
    0 讨论(0)
  • 2020-12-02 15:50

    Set the Row's content visibility to Visibility.Collapsed instead of Hidden. This will make the content stop taking up space, and the row will shrink appropriately.

    0 讨论(0)
提交回复
热议问题