1 minute read

If you haven’t had a chance to mess around with an AdornerDecorator, I highly recommend that you do.  They’re extremely useful because they allow you to overlay WPF controls on top of any other WPF controls.  In WinForms you would have had to use a transparent window acting as an invisible popup to draw over several regions of other controls; it was a pain and generally pretty non-reusable.

The one problem I’ve faced with the supplied Adorner related items is that there isn’t a control in WPF that handles my (and possibly your) most common use-case, which is wanting to just declaratively specify a single piece of content to overlay on top of the child content.  So I took a little time this afternoon to write one for another control I’ve been working on I plan to post about later.

The idea is pretty simple; you start with a ContentControl, change its template to have a AdornerDectorator. Then provide 2 new dependency properties, one for the content to show in the adorner layer and another to control the that content’s visibility.

Here’s what my Overlay class looks like:

The XAML you will need to add to your Generic.xaml:

The end result looks like this when used. The IsOverlayContentVisible should be used in your control/datatemplate triggers to turn the overlay on and off.