代码之家  ›  专栏  ›  技术社区  ›  David Schmitt

如何通过样式设置wpf的grid.rowdefinitions

  •  12
  • David Schmitt  · 技术社区  · 16 年前

    我用了两个 Grid s格式化多个 GridViewColumn.CellTemplate S:

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

    我试图提取 RowDefinition s(所有列相同)转换为 Style :

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

    但是编译器抱怨:

    错误:属性setter 无法设置“rowdefinitions”,因为 它没有可访问的集 访问器。

    这是显而易见的,但不是很有帮助。

    如何避免多次指定行定义(另请参见 Don't Repeat Yourself )缺少对自定义派生的 网格 ?

    1 回复  |  直到 12 年前
        1
  •  8
  •   Tomalak    16 年前

    网格不支持控件模板(信息来自 here 间接地,来自 here )