2012-02-21 11 views
1

現時点では、プロジェクト間でコンバーターをカットして貼り付けるのが少し面倒です。StaticResourceのサブオブジェクトを使用できますか?

コンバーターをフィールド/プロパティとして持つ単一のコンバーターオブジェクトを使用する方法はありますか?

<Application.Resources> 
    <sharedLib:Converters 
     x:Key="Converters" /> 
</Application.Resources> 

<TextBlock Text="{Binding Target, Converter={StaticResource Converters.MakeAllCaps}}" /> 

もしそうでなければ、どのようにコンバーターが一括インポートされるかに関する提案はありますか?

答えて

2

あなたは、このようなリソースディクショナリ内のすべてのあなたのコンバータを定義することができます。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:loc="..."> 

    <loc:BooleanToVisibilityConverter x:Key="BooleanToVisibility" /> 
    <loc:MakeAllCapsConverter x:Key="MakeAllCaps" /> 

    <!-- Define all the common converters here --> 
</ResourceDictionary> 

今、あなたはこのようMergedDictionaries経由でどこからでも、このリソースディクショナリをインポートすることができます。

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Converters.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

<TextBlock Text="{Binding Target, Converter={StaticResource MakeAllCaps}}" /> 
関連する問題