locked
How to put Grid.ColumnDefinitions in style? RRS feed

  • Question

  •  

    I have tried several things but still can't get columnDefinitions in a style (see below)... any ideas?  Thanks

    Code Snippet

     

    <Style x:Key="RowGridStyle" TargetType="{x:Type Grid}">

    <Setter Property="Grid.ColumnDefinitions">

    <Setter.Value>

    <ColumnDefinition Width="200"/>

    <ColumnDefinition Width="*"/>

    </Setter.Value>

    </Setter>

    </Style>

    -- Error 1 The Property Setter 'ColumnDefinitions' cannot be set because it does not have an accessible set accessor.

     

    <Style x:Key="RowGridStyle" TargetType="{x:Type Grid}">

    <Setter Property="Template">

    <Setter.Value>

    <ControlTemplate>

    <Grid.ColumnDefinitions>

    <ColumnDefinition Width="200"/>

    <ColumnDefinition Width="*"/>

    </Grid.ColumnDefinitions>

    </ControlTemplate>

    </Setter.Value>

    </Setter>

    </Style>

     

    -- Error 1 The attached property 'Grid.ColumnDefinitions' is not defined on 'ControlTemplate' or one of its base classes. 

     

     

     

    Tuesday, April 15, 2008 6:22 PM

Answers

  • Sorry, was not attentive.

    First: how can you set the control template for the Grid that doesn't support control templates.

    Second even it was possible Column Definitions require to be wrapped with the Grid parent, so you would have to define additional Grid tags inside the ControlTemplate.

    But I guess that won't be possible for the Grid.

    Tuesday, April 15, 2008 8:24 PM
  • Denis has said pretty clearly that Grid doesn't support ControlTemplate, I think that already answered your question.

    And for how to set readonly property using style setter, try using the hackery trick I used with ItemsControlSorter implementation, aka wrapping the collection adding and removing operations in an attached property which you can set through style setter.

    Hope this helps
    Thursday, April 17, 2008 4:23 AM

All replies

  • Try specifying TargetType property also for ControlTemplate declaration within your setter value.

     

    Tuesday, April 15, 2008 8:10 PM
  • Denis,


    Thanks for the suggestion but it is still not working, still getting Error 1 The attached property 'Grid.ColumnDefinitions' is not defined on 'ControlTemplate' or one of its base classes.  Is that you mean or do you mean something else?  Thanks.

     

    Code Snippet

    <Style x:Key="RowGridStyle" TargetType="{x:Type Grid}">

    <Setter Property="Template">

    <Setter.Value>

    <ControlTemplate TargetType="{x:Type Grid}">

    <Grid.ColumnDefinitions>

    <ColumnDefinition Width="200"/>

    <ColumnDefinition Width="*"/>

    </Grid.ColumnDefinitions>

    </ControlTemplate>

    </Setter.Value>

    </Setter>

    </Style>

     

     

     

    Tuesday, April 15, 2008 8:16 PM
  • Sorry, was not attentive.

    First: how can you set the control template for the Grid that doesn't support control templates.

    Second even it was possible Column Definitions require to be wrapped with the Grid parent, so you would have to define additional Grid tags inside the ControlTemplate.

    But I guess that won't be possible for the Grid.

    Tuesday, April 15, 2008 8:24 PM
  • bummer... no way to do this..?
    Tuesday, April 15, 2008 10:40 PM
  • Denis has said pretty clearly that Grid doesn't support ControlTemplate, I think that already answered your question.

    And for how to set readonly property using style setter, try using the hackery trick I used with ItemsControlSorter implementation, aka wrapping the collection adding and removing operations in an attached property which you can set through style setter.

    Hope this helps
    Thursday, April 17, 2008 4:23 AM
  • Hallo Dan,

    it's only possible to do something like this:

    snippet:

    <Style x:Key="GridRowStyle_1"  

                   TargetType="RowDefinition">  
                <Setter Property="Height"  
                        Value="60" />  
            </Style>  
    <Style x:Key="GridRowStyle_2"  
                   TargetType="RowDefinition">  
                <Setter Property="Height"  
                        Value="100" />  
            </Style> 

    I hope you understand what I mean. My English is not good.

    Greatings Thomas

    Monday, March 9, 2009 12:21 PM