动态访问datatemplates

时间:2012-08-17 16:06:32

标签: wpf

我在template1和template2之间进行了以下xaml:animationTemplate切换。

我想通过将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从中挑选之外,还有更好的方法吗?我宁愿不这样做(即使它可能,因为我在模板中有事件处理程序,我不知道如何删除它们)

0 个答案:

没有答案
相关问题