protected override void OnAttached() { base.OnAttached(); AssociatedObject.SizeChanged += AssociatedObject_SizeChanged; #if alldbg || dbg var win = WPFHelper.FindLogicalParent <Window>(AssociatedObject); DesktopPanelTool.Lib.Debug.WriteLine($"win={win} name={win?.Name}"); #endif }
public void Start(FrameworkElement target, string name = null, object parameters = null, EventHandler completed = null) { if (name == null) { throw new ArgumentNullException(nameof(name)); } switch (name) { case DraggableFrameworkElementBehavior.CancelDragEffectAnimationName: var previewImageCursorWindow = GetPreviewImageCursorWindow(target); InitializeCancelDragStoryboard(previewImageCursorWindow); _translateXAnim.From = previewImageCursorWindow.Left; _translateXAnim.To = _initialLocation.X; _translateYAnim.From = previewImageCursorWindow.Top; _translateYAnim.To = _initialLocation.Y; break; case DraggableFrameworkElementBehavior.BeginDragEffectAnimationName: InitializeBeginDragStoryBoard(target); target.LayoutTransform = _beginScaleTransform; _minWidthBackup = target.MinWidth; _minHeightBackup = target.MinHeight; target.MinWidth = target.MinHeight = 0d; var stackPanel = WPFHelper.FindLogicalParent <StackPanel>(target); if (stackPanel != null) { var idx = stackPanel.Children.IndexOf(target); if (idx > -1) { _previousElement = stackPanel.Children[idx - 1]; _previousElement.Visibility = Visibility.Collapsed; } } break; case DraggableFrameworkElementBehavior.EndDragEffectAnimationName: target.LayoutTransform = _endScaleTransform; if (_previousElement != null) // temporary fix { _previousElement.Visibility = Visibility.Visible; } break; } var animation = GetAnimation(name); if (completed != null) { animation.Completed += completed; } animation.Begin(target); }
void InitializeBeginDragStoryBoard(FrameworkElement target) { Initialize(target); _sourceWindow = WPFHelper.FindLogicalParent <Window>(target); var rpos = target.TranslatePoint(new Point(0, 0), _sourceWindow); _initialLocation = _sourceWindow.PointToScreen(rpos); if (_beginDragStoryboard == null) { (_beginDragStoryboard, _beginScaleTransform) = InitStoryboard(DraggableFrameworkElementBehavior.BeginDragEffectAnimationName, target, 1, 1, 0.1, 0.1); _beginDragStoryboard.Completed += (obj, e) => target.MaxWidth = target.MaxHeight = 0; InitializeEndDragStoryboard(target); } }
internal static void DropWidget(WidgetControl widget, FrameworkElement target, DragEventArgs e) { var targetPanel = WPFHelper.FindLogicalParent <DesktopPanelBase>(target); var sourcePanel = WPFHelper.FindLogicalParent <DesktopPanelBase>(widget); var targetStack = WPFHelper.FindLogicalParent <StackPanel>(target); var sourceStack = WPFHelper.FindLogicalParent <StackPanel>(widget); if (targetPanel != null && sourcePanel != null && targetStack != null && sourceStack != null) { var dropAreaTarget = WPFHelper.FindLogicalParent <WidgetStackPanelDropPlaceHolder>(target); var idxSourceStack = sourceStack.Children.IndexOf(widget); var idxTargetStack = targetStack.Children.IndexOf(dropAreaTarget); var targetIsLargeDropArea = dropAreaTarget.Name == "PermanentWidgetDropPlaceHolder"; #if alldbg || dbg DesktopPanelTool.Lib.Debug.WriteLine($"--------------- drop: {widget.ViewModel.Title} ------------ before:"); DesktopPanelTool.Lib.Debug.WriteLine($"idxTargetStack={idxTargetStack} idxSourceStack={idxSourceStack}"); DesktopPanelTool.Lib.Debug.WriteLine($"sourcePanel==targetPanel:{sourcePanel==targetPanel} targetIsLargeDropArea={targetIsLargeDropArea} idxSourceStack==sourceStack.Children.Count-1:{idxSourceStack == sourceStack.Children.Count - 1}"); #endif if (!((!targetIsLargeDropArea && sourcePanel == targetPanel && Math.Abs(idxTargetStack - idxSourceStack) == 1) || (targetIsLargeDropArea && sourcePanel == targetPanel && idxSourceStack == sourceStack.Children.Count - 1) )) { widget.ViewModel.PanelViewModel.CloseWidget(widget); if (targetIsLargeDropArea) { targetPanel.ViewModel.AddWidget(widget); } else { if (idxTargetStack > idxSourceStack) { idxTargetStack -= 2; } targetPanel.ViewModel.AddWidget(widget, idxTargetStack); } widget.UpdateWidgetViewBindings(sourcePanel, targetPanel); } #if false && dbg DesktopPanelTool.Lib.Debug.WriteLine($"--------------- after:"); widget.ViewModel.PanelViewModel.DumpWidgetsPanelChildren(); #endif } }
internal static void DropWidgetOnDesktop(WidgetControl widget, FrameworkElement target, DragEventArgs e) { var oldpanel = WPFHelper.FindLogicalParent <DesktopPanelBase>(widget); widget.ViewModel.PanelViewModel.CloseWidget(widget); var panel = AddDesktopPanel(); panel.ViewModel.Title = GetNewPanelDefaultTitle(); var p = new POINT(); GetCursorPos(ref p); var gap = (Thickness)widget.FindResource("WindowShadowAreaSize"); var mind = (double)widget.FindResource("DropWidgetOnDesktopPanelMouseRelativeMinPosition"); var maxd = (double)widget.FindResource("DropWidgetOnDesktopPanelMouseRelativeMaxPosition"); panel.Left = p.X - gap.Left - maxd - widget.WidthBackup / 2d; panel.Top = p.Y - gap.Top - mind - widget.HeightBackup / 2d; panel.ViewModel.AddWidget(widget); widget.UpdateWidgetViewBindings(oldpanel, panel); panel.Show(); }