在运行时加载嵌入在 DLL 中的 WPF 控件
在我的 WPF 项目中,我有一个包含多个 WPF 用户控件的 dll。我希望在运行时能够检查数据库中的参数(已实现)并根据该参数(这是一个字符串)能够将特定的 UserControl 加载到我的视图中。
UserControl实际上是一个Canvas,所以它基本上只是根据数据库条目将正确的Canvas放置在View上。
不知道我说清楚了没有,如果有不懂的可以问我。
感谢所有帮助者!
In my WPF project, I have a dll that contains several WPF UserControls. I would like, in runtime, to be able to check a parameter in the database (already implemented) and according to that parameter (which is a string) to be able to load a specific UserControl to my View.
The UserControl is actually a Canvas, so it basically just places the correct Canvas on the View according to the database entry.
I don't know if I was clear, so please ask me if you didn't understand the question.
Thanks to all helpers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种在运行时从 dll 加载控件或类似内容的概念称为反射这是在某些情况下的常见处理方式。尝试用 google 搜索 Reflection in C# 你会发现很多关于它的教程。
基本上你会在运行时加载 dll。然后你就会寻找控制权。一旦找到它,您将创建它的实例并使用它。所有这些都将在运行时发生
另请参阅这个问题供参考
This concept of loading controls or similar things from a dll at runtime is called Reflection and it is a common way of doing things in certain scenarios. Try to google Reflection in C# you will find a lot of tutorials about it.
Basically you will load the dll at runtime. Then you will look for control. Once you find it you will create its instance and use it. All this will happen at runtime
Also see this question for reference