2011-08-30 45 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現在)可以計算出:

  • 提取所有的東西,你在文本框設置到風格,還可以再敷在這兩種情況下
  • 定義文本塊本身作爲一種資源,並在兩個模板
相關問題