private static void TargetElementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DragControlHelper Helper = d as DragControlHelper; if (Helper == null) { return; } FrameworkElement oldTarget = e.OldValue as FrameworkElement; Helper.DetachTatgetEvents(oldTarget); bool isAutoReset = oldTarget != null?GetIsAutoResetES(oldTarget) : false; FrameworkElement newTarget = e.NewValue as FrameworkElement; if (newTarget == null || newTarget is DragControlHelper || newTarget.RenderSize.IsEmpty || double.IsNaN(newTarget.RenderSize.Width) || double.IsNaN(newTarget.RenderSize.Height) || !GetIsSelectable(newTarget)) { Helper.Visibility = Visibility.Collapsed; if (isAutoReset) { //重置可编辑属性 SetIsEditable(oldTarget, false); SetIsSelectable(oldTarget, false); } return; } Helper.AttachTatgetEvents(newTarget); int Zindex = Panel.GetZIndex(newTarget); if (Zindex >= Panel.GetZIndex(Helper)) { Panel.SetZIndex(Helper, Zindex + 1); } double Y = CorrectDoubleValue(Canvas.GetTop(newTarget)); double X = CorrectDoubleValue(Canvas.GetLeft(newTarget)); Canvas.SetTop(Helper, Y); Canvas.SetLeft(Helper, X); Helper.Width = newTarget.ActualWidth; Helper.Height = newTarget.ActualHeight; }
private static void TargetElementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DragControlHelper Helper = d as DragControlHelper; if (Helper == null) { return; } FrameworkElement Target = e.OldValue as FrameworkElement; Helper.DetachTatgetEvents(Target); Target = e.NewValue as FrameworkElement; if (Target == null || Target is DragControlHelper || Target.RenderSize.IsEmpty || double.IsNaN(Target.RenderSize.Width) || double.IsNaN(Target.RenderSize.Height) || !GetIsSelectable(Target)) { Helper.Visibility = Visibility.Collapsed; return; } Helper.AttachTatgetEvents(Target); int Zindex = Panel.GetZIndex(Target); if (Zindex >= Panel.GetZIndex(Helper)) { Panel.SetZIndex(Helper, Zindex + 1); } double Y = CorrectDoubleValue(Canvas.GetTop(Target)); double X = CorrectDoubleValue(Canvas.GetLeft(Target)); Canvas.SetTop(Helper, Y); Canvas.SetLeft(Helper, X); Helper.Width = Target.ActualWidth; Helper.Height = Target.ActualHeight; }