Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Triggers on Grid RowDefinitions?

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:

<RowDefinition Height="2*">
    <RowDefinition.Style>
        <Style>
            <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>

This compiles, throws no errors, but doesn't seem to have any effect. Is there something I'm missing, or does the Grid not allow its rows to resize after the form is drawn or something to that effect?

like image 997
GWLlosa Avatar asked Feb 24 '11 13:02

GWLlosa


People also ask

How do I create a grid with three rows?

The following example creates a Grid with three rows. The Height of the first row is set to the value Auto, which distributes height evenly based on the size of the content that is within that row. The height of the second row and third row are set to 2* and * respectively. The second row gets 2/3 of the remaining space and the third row gets 1/3.

What is row definition in Xamarin grid?

Grid. Row Definitions Property Xamarin. Forms Provides the interface for the bound property that gets or sets the collection of RowDefinition objects that control the heights of each row. A RowDefinitionCollection for the Grid instance. RowDefinitions is an ordered set of RowDefinition objects that determine the height of each row.

How to get a list of rowdefinition objects defined on grid?

Xaml. Controls Gets a list of RowDefinition objects defined on this instance of Grid. A list of RowDefinition objects defined on this instance of Grid. The following example creates a Grid with three rows. The Height of the first row is set to the value Auto, which distributes height evenly based on the size of the content that is within that row.

What is rowdefinitioncollection in Salesforce grid?

A RowDefinitionCollection for the Grid instance. RowDefinitions is an ordered set of RowDefinition objects that determine the height of each row. Each successive RowDefintion controls the width of each successive row.


1 Answers

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>
like image 58
Fredrik Hedblad Avatar answered Sep 19 '22 18:09

Fredrik Hedblad