Is it possible to use Triggers on Grid RowDefinitions?

后端 未结 2 1251
无人及你
无人及你 2021-02-19 04:25

I have a grid whose rows need to be resized dynamically based on the view model. I\'d like to do something like the following:



        
相关标签:
2条回答
  • 2021-02-19 04:34

    I think the only problem with your Xaml code is that you're overwriting the DataTrigger by setting Height explictly on the RowDefinition. Try with using a Setter instead

    <RowDefinition>
        <RowDefinition.Style>
            <Style>
                <Setter Property="RowDefinition.Height" Value="2*"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=ShowSection}" Value="True">
                        <Setter Property="RowDefinition.Height" Value="2*"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=ShowSection}" Value="False">
                        <Setter Property="RowDefinition.Height" Value="0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </RowDefinition.Style>
    </RowDefinition>
    
    0 讨论(0)
  • 2021-02-19 04:56

    I know this post is 3 years old, but still it might help someone.

    <RowDefinition>
        <RowDefinition.Style>
            <Style TargetType="RowDefinition">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=ShowSection}" Value="True">
                        <Setter Property="Height" Value="2*"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=ShowSection}" Value="False">
                        <Setter Property="Height" Value="0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </RowDefinition.Style>
    </RowDefinition>
    

    I was in same situation, i managed to get it working by setting TargetType to RowDefinition.

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