I got a scenario, where I have to have some controls pop up on top of some other controls, basically just like a popup.
So in my first attempt i used a Popup, but this element has some behavior, which gave me headaches. The biggest problem was, that the popup won't follow the original pop-up location when i.e. the window is moved or the content of the panel is scrolled up or down.
Then I thought about using an adorner. Everything worked fine, except that I cannot interact with any control in my adorner layer.
Here's my adorner class:
using
System;using
System.Collections.Generic;using
System.Text;using
System.Windows.Documents;using
System.Windows.Controls.Primitives;using
System.Windows.Media;using
System.Windows;using
System.Windows.Input;using
System.Windows.Controls;using
System.Windows.Shapes;using
System.Windows.Media.Animation;namespace
DSA.WPF.Controls.General{
classPopupAdorner : Adorner{
privateBorder _child;privatedouble _padding;public PopupAdorner(UIElement adornedElement, UIElement content):
base(adornedElement){
_padding = 3D;
_child =
newBorder();_child.Width = adornedElement.RenderSize.Width + 2 * _padding;
_child.SnapsToDevicePixels =
true;_child.Padding =
newThickness(_padding);_child.BorderBrush =
Brushes.Gray;_child.BorderThickness =
newThickness(1D);_child.Background =
Brushes.LightGray;_child.Child = content;
}
protectedoverrideSize MeasureOverride(Size availableSize){
_child.Measure(availableSize);
return _child.DesiredSize;}
protectedoverrideSize ArrangeOverride(Size finalSize){
_child.Arrange(
newRect(newPoint(-_padding, -_padding), finalSize));return finalSize;}
protectedoverrideVisual GetVisualChild(int index){
return _child;}
protectedoverrideint VisualChildrenCount{
get { return 1; }}
}
}
MSDN tells me, that it basically should catch mouse events etc., but somehow it's not working. If I click something, the clicks are handled in the layer below, not in the adornerlayer. I already tried the IsHitTestVisible property, but to no avail.
Probably the adorner layer isn't the best approach either. Anyone got an idea,of how to solve such a problem?