开发者

Proper way to expose third party visual control in MEF

开发者 https://www.devze.com 2023-01-21 03:29 出处:网络
What is the proper way to do that? Let\'s say we have some third party library in our project and we need to provide an access to some controls which are sealed.

What is the proper way to do that? Let's say we have some third party library in our project and we need to provide an access to some controls which are sealed. New widgets will be created and added to the application using MEF and they should be able to import some controls from the core application. So how to export those controls 开发者_Python百科properly?


If you cannot modify the original class (e.g. ThirdPartyComponent), then you can do the export via a property on another class (e.g. ThirdPartyComponentExporter):

public class ThirdPartyComponentExporter
{
   [Export(typeof(ThirdPartyComponent))]
   public ThirdPartyComponent Foo
   {
      get
      {
         return new ThirdPartyComponent();
      }
   }
}

For visual controls, you may have to use CreationPolicy.NonShared to prevent MEF from reusing the same instance in different locations.


What about wrapping the third party controls in "export" classes and then access this control through the wrapper?

0

精彩评论

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