void MakeAdorner(UIElement uiElement, object data, object target, bool isOpening, bool canDrop, string message) { // get adorner layer FrameworkElement el = this.AssociatedObject; while (el != null && (!(el is UserControl) || AdornerLayer.GetAdornerLayer(el) == null)) { el = (FrameworkElement)VisualTreeHelper.GetParent(el); } if (el != null) { _adornerLayer = AdornerLayer.GetAdornerLayer(el); // make adorner if (AdornerType == null) { _adorner = new DropAdorner(uiElement, data, target, isOpening, canDrop, message); } else { _adorner = (System.Windows.Documents.Adorner)Activator.CreateInstance(AdornerType, new object[] { uiElement, data, target, isOpening, canDrop, message }); } _adornerLayer.Add(this._adorner); // set adorner z-order var setZOrderMethodInfo = _adornerLayer.GetType().GetMethod("SetAdornerZOrder", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); setZOrderMethodInfo.Invoke(_adornerLayer, new object[] { _adorner, 1 }); } }
/// <summary> /// Update adorner’s order. /// </summary> private void UpdateOrder() { if (_adornerLayer == null || _adorner == null) { return; } try { _adornerLayer.GetType().GetMethod("SetAdornerZOrder", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) .Invoke(_adornerLayer, new object[] { _adorner, Order }); } catch { // ignored } }