private static void ApplyContentAdorner(FrameworkElement target) { var adornerLayer = AdornerLayer.GetAdornerLayer(target); if (adornerLayer == null) { // windows do not have an adorner layer, try their first (and only) child target = LogicalTreeHelper.GetChildren(target).OfType <FrameworkElement>().FirstOrDefault(); if (target == null) { return; // no children found } adornerLayer = AdornerLayer.GetAdornerLayer(target); if (adornerLayer == null) { return; // nothing adornable found } } var adorner = new ContentAdorner(target); adornerLayer.Add(adorner); }
private static void ApplyContentAdorner(FrameworkElement target) { var adornerLayer = AdornerLayer.GetAdornerLayer(target); if (adornerLayer == null) { // windows do not have an adorner layer, try their first (and only) child target = LogicalTreeHelper.GetChildren(target).OfType<FrameworkElement>().FirstOrDefault(); if (target == null) return; // no children found adornerLayer = AdornerLayer.GetAdornerLayer(target); if (adornerLayer == null) return; // nothing adornable found } var adorner = new ContentAdorner(target); adornerLayer.Add(adorner); }