Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set WPF's Grid.RowDefinitions via Style

Tags:

styles

wpf

grid

I'm using a couple of Grids to format multiple GridViewColumn.CellTemplates:

<ListView SharedSizeScope="true">
  <ListView.View>
    <GridView>
      <GridViewColumn>
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition SharedSizeGroup="foo" />
                <!-- ... -->

I tried to extract the RowDefinitions (which are the same for all columns) into a Style:

<Style TargetType="{x:Type Grid}">
  <Setter Property="RowDefinitions">
    <Setter.Value>
      <RowDefinition SharedSizeGroup="foo" />
      <!-- ... -->

But the compiler complains:

Error: The Property Setter 'RowDefinitions' cannot be set because it does not have an accessible set accessor.

Which is kind of obvious, but not very helpful.

How could I avoid specifying the row definitions multiple times (see also Don't Repeat Yourself) short of coding up a custom derivation of the Grid?

like image 896
David Schmitt Avatar asked Dec 10 '08 08:12

David Schmitt


1 Answers

Grid doesn't support control templates (info taken from here and, indirectly, from here).

like image 136
Tomalak Avatar answered Sep 29 '22 23:09

Tomalak