如何通过样式设置WPF的Grid.RowDefinitions

12
我正在使用几个Grid来格式化多个GridViewColumn.CellTemplate:
<ListView SharedSizeScope="true">
  <ListView.View>
    <GridView>
      <GridViewColumn>
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition SharedSizeGroup="foo" />
                <!-- ... -->

我试图将所有列都相同的RowDefinition提取到一个Style中:

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

但编译器报错:

Error: 属性设置器 'RowDefinitions' 无法设置,因为它没有可访问的设置访问器。

这有点显而易见,但不太有帮助。

除了编写自定义派生类 Grid,我怎样才能避免多次指定行定义(也可参见不要重复自己)?

1个回答

8

Grid不支持控件模板(信息来自这里和间接地来自这里)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接