开发者

Create WPF Window at Runtime

Is it possible to create a WPF Window control at runtime?

I'm thinking of a somewhat hack-ish solut开发者_如何学编程ion to a problem, but I would essentially like to be able to have a dll which allows me to dynamically load a WPF Window and compile it's associated code behind (from an xaml and cs file respectivly). I assume I would also have to manually load any assemblies that the codebehind requires.

This would give me the ability to create modular addons which allow for Windows to be run from another application without being compiled into the source.

There are a few SO posts about this topic, but none seem to deal with window/code creation specifically.

If it's not possible (or just really not reccomended) thoughts as to alternatives would be greatly appreciated.

Cheers,

Kyle


I would recommend looking into technologies like MEF instead. This is now included directly in the Framework, but allows you to "inject" 3rd party code/windows/views/viewmodels directly into your application, without distributing your application.

Instead of trying to compile the code in your application, you can provide simple interfaces, and let MEF compose the application for you. This is a much easier, more flexible option.

I've used this before where I've had a contract for ViewModels and a contract for ResourceDictionaries containing DataTemplates. This allows you to do fully-dynamic runtime injection of logic (ViewModel) with their associated Views, and just wrap it up in a Window at runtime.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜