2011-08-30 64 views
1

目前,我有我申请到细胞数据模板,让他们的风格以某种方式:我可以将现有数据模板添加到控件的资源吗?

<DataTemplate x:Key="percentageCellContentTemplate4"> 
    <TextBlock VerticalAlignment="Center" Height="17" TextAlignment="Right" Margin="-1,-1,-1,-1" Background="White" Text="{Binding Converter={StaticResource PercentScale4}, ConverterParameter=' \{0:P\}'}" ToolTip="{Binding}"/> 
</DataTemplate> 

现在我有,我需要添加为DataGrid的资源范围内键入模板的情况下。目前,这是工作:

<xcdg:DataGridControl.Resources> 
    <ResourceDictionary> 
      <DataTemplate DataType="{x:Type s:Decimal}"> 
       <!-- This is exactly percentageCellContentTemplate4 - if someone can find a way to inherit this dataTemplate, free poutine. --> 
       <TextBlock VerticalAlignment="Center" Height="17" TextAlignment="Right" Margin="-1,-1,-1,-1" Background="White" Text="{Binding Converter={StaticResource PercentScale4}, ConverterParameter=' \{0:P\}'}" ToolTip="{Binding}"/> 
      </DataTemplate> 
    </ResourceDictionary> 
</xcdg:DataGridControl.Resources> 

谁能想到,我避免复制粘贴此完全相同的模板和相似的地方,我需要它的方法吗?

感谢

回答

3

怎么是这样的:

<DataTemplate DataType="{x:Type s:Decimal}"> 
    <ContentPresenter ContentTemplate="{StaticResource percentageCellContentTemplate4}" /> 
</DataTemplate> 

编辑:测试,它似乎工作。

+0

辉煌引用它,我会记住这一招。谢谢! – Alain

+0

@Alain:非常欢迎,很高兴帮助:) –

0

虽然我认为HB的答案应该工作,其他两种可能性浮现在脑海中(不手头有WPF现在)可以计算出:

  • 提取所有的东西,你在文本框设置到风格,还可以再敷在这两种情况下
  • 定义文本块本身作为一种资源,并在两个模板
相关问题