private void UserControl_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    ViewForegroundControlHeader control = sender as ViewForegroundControlHeader;
                    if (control == null)
                    {
                        return;
                    }
                    else if (control.DataContext == null)
                    {
                        return;
                    }

                    DependencyObject parentTabItemDependencyObject = Xvue.Framework.Views.WPF.VisualTreeBrowser.GetAncestorByType(this, typeof(TabItem));

                    if (parentTabItemDependencyObject == null)
                    {
                        return;
                    }

                    TabItem parentTabItem = parentTabItemDependencyObject as TabItem;

                    if (!parentTabItem.IsSelected)
                    {
                        return;
                    }

                    ViewModelImagingLayer toMoveImageLayer = control.DataContext as ViewModelImagingLayer;
                    toMoveImageLayer.ImagingComponent.InitMoveComponent();

                    DataObject data = new DataObject();
                    ViewModelImagingLayerDragObject dragObject = new ViewModelImagingLayerDragObject(toMoveImageLayer, control.ActualWidth);
                    data.SetData("stackPanelDragItem", dragObject);

                    DependencyObject parentTabControlDependencyObject = Xvue.Framework.Views.WPF.VisualTreeBrowser.GetAncestorByType(this, typeof(TabControl));

                    DragDrop.DoDragDrop(control, data, DragDropEffects.Move);

                    //Prevent popup from not closing
                    if (parentTabControlDependencyObject != null)
                    {
                        TabControl parentTabControl = parentTabControlDependencyObject as TabControl;
                        parentTabControl.CaptureMouse();
                        parentTabControl.ReleaseMouseCapture();
                    }
                }
            }
            catch { }
        }
        private void BeginDrag()
        {
            double lastMouseX = Mouse.GetPosition(tabPanel).X;

            TabControl.CaptureMouse();
            draggedTab   = FindTabItemOn(lastMouseX);
            selectedItem = tabs[TabControl.SelectedIndex];
            if (draggedTab != null)
            {
                draggedTabDeltaX = lastMouseX - draggedTab.RenderTransform.Value.OffsetX;
                if (!draggedTab.IsSelected)
                {                                                  // if draggedTab is not the selected one,
                    draggedTab.SetValue(Panel.ZIndexProperty, 50); // rearrange it to the top of unselected tab
                    TabControl.UpdateLayout();
                }
            }
        }
Exemplo n.º 3
0
        private static void TabControl_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            TabControl tabControl = (TabControl)sender;
            Point      point      = e.GetPosition(tabControl);

            if (tabControl.IsMouseCaptured)
            {
                TabTearOffBehavior.UpdateDragWindowLocation(tabControl);
                Window dropWindow = TabTearOffBehavior.GetWindowMouseIsOver(e);
                if (dropWindow == null)
                {
                    return;
                }
                if (!dropWindow.IsActive)
                {
                    dropWindow.Activate();
                }
                ITabTearOffHandler targetHandler;
                TabControl         targetTabControl = TabTearOffBehavior.FindTargetTabControl(dropWindow, out targetHandler);
                Panel panel = ControlMethods.GetPanel(targetTabControl);
                if (TabTearOffBehavior.IsMouseInDropLocation(e, targetTabControl, panel))
                {
                    if (TabTearOffBehavior._adorner == null || !TabTearOffBehavior._adorner.AdornedElement.Equals(targetTabControl))
                    {
                        if (TabTearOffBehavior._adorner != null)
                        {
                            TabTearOffBehavior._adorner.Detach();
                        }
                        TabTearOffBehavior._adorner = new InsertionAdorner(targetTabControl, panel.GetOrientation());
                    }
                    TabTearOffBehavior._adorner.UpdateLocation(e);
                }
                else if (TabTearOffBehavior._adorner != null)
                {
                    TabTearOffBehavior._adorner.Detach();
                    TabTearOffBehavior._adorner = null;
                }
            }
            else if (TabTearOffBehavior.IsSufficientDragMove(point))
            {
                Rectangle contentRectangle = TabTearOffBehavior.CreateRectangle((Visual)TabTearOffBehavior.GetContent(tabControl));
                Rectangle tabItemRectangle = TabTearOffBehavior.CreateRectangle(TabTearOffBehavior._activeTabItem);
                Panel.SetZIndex(tabItemRectangle, 10);
                StackPanel stackPanel = new StackPanel
                {
                    Orientation = tabControl.TabStripPlacement == Dock.Right || tabControl.TabStripPlacement == Dock.Left ? Orientation.Horizontal : Orientation.Vertical,
                    Children    =
                    {
                        tabItemRectangle
                    }
                };
                stackPanel.Children.Insert(tabControl.TabStripPlacement == Dock.Right || tabControl.TabStripPlacement == Dock.Bottom ? 0 : 1, contentRectangle);
                TranslateTransform translateTransform = new TranslateTransform();
                switch (tabControl.TabStripPlacement)
                {
                case Dock.Bottom:
                    translateTransform.Y = -1d;
                    break;

                case Dock.Left:
                    translateTransform.X = 1d;
                    break;

                case Dock.Right:
                    translateTransform.X = -1d;
                    break;

                case Dock.Top:
                    translateTransform.Y = 1d;
                    break;
                }
                tabItemRectangle.RenderTransform = translateTransform;
                TabTearOffBehavior._dragWindow   = new Window
                {
                    Topmost            = true,
                    AllowsTransparency = true,
                    WindowStyle        = WindowStyle.None,
                    IsHitTestVisible   = false,
                    SizeToContent      = SizeToContent.WidthAndHeight,
                    Background         = Brushes.Transparent,
                    Content            = new Border
                    {
                        Child   = stackPanel,
                        Opacity = 0.75
                    }
                };
                TabTearOffBehavior.UpdateDragWindowLocation(tabControl);
                TabTearOffBehavior._dragWindow.Show();
                tabControl.MouseLeave -= TabTearOffBehavior.TabControl_MouseLeaveOrLostCapture;
                tabControl.CaptureMouse();
                e.Handled = true;
            }
        }