0

次のxamlがあります。animationTemplateはtemplate1とtemplate2を切り替えます。

複数のコントロールが同じanimationTemplateを使用できるように、animationTemplateをリソースディクショナリに配置して、これをより再利用可能にしたいと思います。問題は、アニメーションテンプレートにtemplate1とtemplate2への参照があるため、animationTemplateを辞書に入れると、animationTemplateがテンプレート1と2を見つけられないため、エラーが発生することです。

    <Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Dictionary1.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <DataTemplate x:Key="template1" />
        <DataTemplate x:Key="template2" />
        <DataTemplate x:Key="animationTemplate" />
    </ResourceDictionary>
</Window.Resources>
<ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource animationTemplate}" />

すべてのテンプレートペアを辞書に入れ、contentTemplateSelectorを使用してそれらから選択する以外に、より良い方法はありますか?私はこれをしたくありません(テンプレートにイベントハンドラーがあり、それらをどのように削除するかわからないため、可能であっても)

4

0 に答える 0