如何通过Style设置WPF的Grid.RowDefinitions

Dav*_*itt 12 wpf grid styles

我用几个Grids来格式化多个GridViewColumn.CellTemplates:

<ListView SharedSizeScope="true">
  <ListView.View>
    <GridView>
      <GridViewColumn>
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition SharedSizeGroup="foo" />
                <!-- ... -->
Run Code Online (Sandbox Code Playgroud)

我试图将RowDefinitions(对于所有列都相同)提取到Style:

<Style TargetType="{x:Type Grid}">
  <Setter Property="RowDefinitions">
    <Setter.Value>
      <RowDefinition SharedSizeGroup="foo" />
      <!-- ... -->
Run Code Online (Sandbox Code Playgroud)

但编译器抱怨:

错误:无法设置Property Setter'RowDefinitions',因为它没有可访问的set访问器.

这有点明显,但不是很有帮助.

我怎么能避免多次指定行定义(参见不要重复自己),而不是编写自定义派生的Grid

Tom*_*lak 8

网格不支持控制模板(从此处获取信息,间接地从此处获取).