如何从外部集添加类型工具箱中的控制? (WPF) [英] How to add types from external assembly to toolbox control? (WPF)

查看:171
本文介绍了如何从外部集添加类型工具箱中的控制? (WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做这样的事情在我的WPF应用程序:

I am trying to do something like this in my WPF application:

    ToolboxControl ctrl = new ToolboxControl();
    Assembly assembly = Assembly.LoadFile(file);
    var category = new ToolboxCategory(assembly.GetName().Name);
    foreach (Type t in assembly.GetTypes())
    {
        var wrapper = new ToolboxItemWrapper(t, t.Name);
        category.Add(wrapper);
    }
    ctrl.Categories.Add(category);

即。加入ToolboxItemWrappers在装配中每种类型。然而,最后一行抛出以下异常(见图片)

i.e. adding ToolboxItemWrappers for each type found in an assembly. However the last line throws the following exception (see image)

外部组件的所有依存关系也可参考在main(WPF)应用程序。那么,什么是错在这里,如何解决这个问题?

All dependencies of the external assembly are also referenced in the main (WPF) application. So what's wrong here and how to fix it?

推荐答案

是文件中的CustomLibrary组装?如果不是,钩此事件​​AppDomain.CurrentDomain.AssemblyResolve在你的应用程序,并加载任何其他组件的组合件的文件路径参考。如果CustomLibrary或其他DLL不在GAC这是必需的。

Is the CustomLibrary assembly in the file? If not, hook to this event AppDomain.CurrentDomain.AssemblyResolve in you app, and load any other assemblies that the assembly at the filePath references to. It is required if CustomLibrary or other dlls are not in GAC.

这篇关于如何从外部集添加类型工具箱中的控制? (WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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