tags:

views:

104

answers:

2

I'm trying to do something like this...

<Style
    x:Key="TwoByTwoGridStyle"
    TargetType="Grid">
    <Setter
        Property="Grid.RowDefinitions">
        <Setter.Value>
            <ControlTemplate>
                <RowDefinition
                    Height="*" />
                <RowDefinition
                    Height="Auto" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter
        Property="Grid.ColumnDefinitions">
        <Setter.Value>
            <ControlTemplate>
                <ColumnDefinition
                    Width="*" />
                <ColumnDefinition
                    Width="Auto" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

ControlTemplate is not right. I get the error: "Property VisualTree does not support values of type RowDefinition". Is there some way to signify a collection of row/column definitions? Or, is there some other way to create a style/template for a 2x2 Grid?

Thanks.

A: 

The RowDefinitions property is not of type ControlTemplate, so it doesn't make sense to assign it a ControlTemplate. You should assign a RowDefinitionCollection instead :

<Style
    x:Key="TwoByTwoGridStyle"
    TargetType="Grid">
    <Setter
        Property="Grid.RowDefinitions"
        <Setter.Value>
            <RowDefinitionCollection>
                <RowDefinition
                    Height="*" />
                <RowDefinition
                    Height="Auto" />
            </RowDefinitionCollection>
        </Setter.Value>
    </Setter>
    <Setter
        Property="Grid.ColumnDefinitions"
        <Setter.Value>
            <ColumnDefinitionCollection>
                <ColumnDefinition
                    Width="*" />
                <ColumnDefinition
                    Width="Auto" />
            </ColumnDefinitionCollection>
        </Setter.Value>
    </Setter>
</Style>
Thomas Levesque
Thanks for the answer, but it doesn't work. I get this error: "Type 'RowDefinitionCollection' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter."
DanM
OK... maybe it's not possible then
Thomas Levesque
A: 

I'm pretty sure now that the answer is: "can't be done". Please correct me if I'm wrong.

DanM