2008-12-10 57 views
11

我使用的是一對夫婦的Grid s到格式化多個GridViewColumn.CellTemplate S設定WPF的Grid.RowDefinitions:如何通過樣式

<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: The Property Setter 'RowDefinitions' cannot be set because it does not have an accessible set accessor.

這是顯而易見的,但不是很有幫助。

我怎樣才能避免多次指定行定義(另請參閱Don't Repeat Yourself),然後編寫自定義派生的Grid

回答

7

網格不支持控件模板(信息摘自here,間接從here)。