来自另一个程序集的 WPF DataTemplate [英] WPF DataTemplate from another assembly

查看:27
本文介绍了来自另一个程序集的 WPF DataTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 DataTemplateSelector 中引用位于另一个程序集中的 DataTemplate.

Is it possible to reference DataTemplate which is located in another assembly in DataTemplateSelector.

目前我有这样的事情:

public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        var element = container as FrameworkElement;

        if (element != null && item != null && item is BrowserBaseViewModel)
        {
            return element.FindResource("BrowserDataTemplate") as DataTemplate;
        }
        return null;
    }

但它仅适用于当前程序集.

But it works only with current assembly.

推荐答案

当然,在您的 app.xaml 中写入一个 ResourceDictionaryinclude",以便可以在您的应用程序中找到字典.

Sure, write in your app.xaml a ResourceDictionary "include" so the dictionary can be found in your application.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/MyOtherAssembly;component/MyAssemblyXaml.xaml" />

现在将找到您的数据模板,因为资源查找将查找 app.xaml 资源,并找到您引用的 xaml.

Now your data template will be found, because the resource lookup will look into the app.xaml resources, and find your referenced xaml.

这篇关于来自另一个程序集的 WPF DataTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆