I am trying to create an overlay in wpf (with a dimming background), similar to the ones you can find on the Internet for popup images. I would like it to be reused in more than one part of the application with different types of content.
this is a temporary adorner constructor code (just a try)
private readonly Grid _grid = new Grid(); public DarkOverlayAdorner(UIElement adornedElement, Object content) : base(adornedElement) { _grid.Background = new SolidColorBrush(Color.FromArgb(99, 0, 0, 0)); IsHitTestVisible = true; var visual = content as UIElement; if (visual != null) _grid.Children.Add(visual); }
Also, in the class (of course), I have ovverrides MeasureOverride and ArrangeOverride to give adorner the correct size of the stolen item, GetVisualChild and VisualChildCount ...
The problem is that adorner is correctly displayed, but no events or behavior are applied to the decorated element. For instance:
AdornerLayer layer = AdornerLayer.GetAdornerLayer(textBoxProva); layer.Add(new DarkOverlayAdorner(textBoxProva, new Button{Content = "prova"}));
A button is displayed here, but I canβt click the button, and no effects will be applied when the mouse button is clicked. I still can not understand the problem.
source share