1

現時点では、プロジェクト間のコンバーターの切り取りと貼り付けに少し退屈を感じています。

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

例:

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

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

そうでない場合、コンバーターを一括インポートする方法について何か提案はありますか?

4

1 に答える 1

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}}" />
于 2012-02-21T12:40:29.213 に答える