简化XAML代码

时间:2016-08-19 11:56:44

标签: wpf xaml

我仍然非常生气,WPF中的样式,模板和类似内容有多么复杂。我试图弄清楚如何避免重复的XAML代码:

<xcdg:DataGridControl Grid.Row="1">
  <xcdg:DataGridControl.View>
    <xcdg:TableflowView UseDefaultHeadersFooters="False">
      <xcdg:TableflowView.FixedHeaders>
        <DataTemplate>
          <xcdg:ColumnManagerRow/>
        </DataTemplate>
      </xcdg:TableflowView.FixedHeaders>
    </xcdg:TableflowView>
  </xcdg:DataGridControl.View>  

  </xcdg:DataGridControl>
  <xcdg:DataGridControl Grid.Row="1" Grid.Column="1">
    <xcdg:DataGridControl.View>
      <xcdg:TableflowView UseDefaultHeadersFooters="False">
        <xcdg:TableflowView.FixedHeaders>
          <DataTemplate>
            <xcdg:ColumnManagerRow/>
          </DataTemplate>
        </xcdg:TableflowView.FixedHeaders>
      </xcdg:TableflowView>
    </xcdg:DataGridControl.View>
  </xcdg:DataGridControl>  

我希望有这样的东西:

<ViewSettings>
<xcdg:DataGridControl.View>
  <xcdg:TableflowView UseDefaultHeadersFooters="False">
    <xcdg:TableflowView.FixedHeaders>
      <DataTemplate>
        <xcdg:ColumnManagerRow/>
      </DataTemplate>
    </xcdg:TableflowView.FixedHeaders>
  </xcdg:TableflowView>
</xcdg:DataGridControl.View>
</ViewSettings>  

<xcdg:DataGridControl Grid.Row="1" Grid.Column="1">
  ViewSettings
<xcdg:DataGridControl/>
<xcdg:DataGridControl Grid.Row="1" Grid.Column="1">
  ViewSettings
<xcdg:DataGridControl/>

1 个答案:

答案 0 :(得分:2)

xcdg创建自定义样式:DataGridControl ,设置View属性,将其存储在FrameworkElement资源字典中,并使用StaticResource引用它。

此处它存储在父网格资源字典中。

ALTER DATABASE db_name CHARACTER SET utf8 COLLATE utf8_general_ci;