Setting Grid RowDefinitions/ColumnDefinitions properties in a style

Viewed 5660

Suppose that you have 2 or more grids that share the same structure (Rows/Columns count and properties are equal).

Is it possible to create a Style and set RowDefinitions/ColumnDefinitions?

I have tried that. But I get this exception when the application tries to parse the xaml:

Xamarin.Forms.Xaml.XamlParseException: Position 14:9. Property Value is null or is not IEnumerable

My Source code:

<StackLayout>
    <StackLayout.Resources>
        <ResourceDictionary>
            <Style TargetType="Grid">
                <Setter Property="RowDefinitions">
                    <Setter.Value>
                        <RowDefinition />
                        <RowDefinition />
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </StackLayout.Resources>

    <Grid>
        <Label Grid.Row="0" Text="(Grid #1) Row #1" />
        <Label Grid.Row="1" Text="(Grid #1) Row #2" />
    </Grid>

    <Grid>
        <Label Grid.Row="0" Text="(Grid #2) Row #1" />
        <Label Grid.Row="1" Text="(Grid #2) Row #2" />
    </Grid>

    <Grid>
        <Label Grid.Row="0" Text="(Grid #3) Row #1" />
        <Label Grid.Row="1" Text="(Grid #3) Row #2" />
    </Grid>
</StackLayout>

Position 14:9 in the exception refers to the first <RowDefinition /> tag.

5 Answers
Related