Is it possible to style a 2x2 grid in WPF?

I am 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

wrong. I get the error: "Property VisualTree

does not support type values RowDefinition

". Is there a way to denote a collection of row / column definitions? Or, is there any other way to create a style / template for a 2x2 grid?

Thank.

+2


source to share


2 answers


Now I'm sure the answer is "can't be done". Please correct me if I am wrong.



0


source


The RowDefinitions property is not of type ControlTemplate, so it makes no sense to assign a ControlTemplate to it. Instead, you must assign a RowDefinitionCollection:



<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>

      

0


source







All Articles