How to get an Adorner layer without the use of AdornerLayer.GetAdornerLayer

Hello,

I am currently working on a plugin (I cannot give any more information about this yet I will post it on my blog shortly) using WPF. The main application that hosts all plugins uses the System.Addin (.Net 3.5 version). While developing the plugin I got into a brick wall… Basically I was calling the AdornerLayer.GetAdornerLayer, passing the instance of the plugin UI as parameter yet the method was returning a big and ugly null.

I started digging into the problem and had a look at how the Addin system works. Basically all addins are sandboxed into a seperate appdomain and there is no possible way how you can get the instance of the AdornerLayer of the main window (Or better there is no easy way of doing that) …

I solved this problem by creating an AdornerDecorator as an element in my XAML and then get the adorner layer of this AdornerDecorator. So the XAML would look something like this

<UserControl>

<AdornerDecorator Name=”myAdornerLayer”>

….other XAML here

</AdornerDecorator>

</UserControl>

Then in C# i just call the myAdornerLayer.AdornerLayer and do what ever I want with it. This solution does not help if you want an adorner layer for all the main window that is hosting your plugin, the adorner layer will ONLY cover the surface area of the plugin. Yet if you do not need the whole area of the main window but only the surface area of the plugin, this solution should work just fine ….

Hope you find this useful…

Looking forward to post the plugin online….. I am sure you will love it :P

Best Regards

About these ads

2 thoughts on “How to get an Adorner layer without the use of AdornerLayer.GetAdornerLayer

  1. Are you trying to get the adorner layer of the addin while in the host? If so, and the addin is in a separate appdomain, then when you access the adorner layer aren’t you leaking that type across the appdomain?

    If that is the case, it is possible to load the addin in the same appdomain in the host if that is necessary and you are willing to forfeit isolation. I’m looking forward to the addin!

  2. Hi there,

    Yes you are totally right the addin is loaded in a seperate AppDomain and that is the reason why I created the AdornerDecorater. By having the AdornerDecorator I can then get it’s AdornerLayer and paint on that layer as much as I want :)
    So basically by having the AdornerDecorator I do not need anymore to access the AdornerLayer of the main window that is on the other AppDomain :P

    Regards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s