private void UserControl_DragEnter(object sender, DragEventArgs e)
        {
            try
            {
                if (_isDragging)
                {
                    return;
                }

                if (e.Data.GetDataPresent("stackPanelDragItem"))
                {
                    ViewForegroundControlHeader control = sender as ViewForegroundControlHeader;
                    if (control == null)
                    {
                        return;
                    }
                    else if (control.DataContext == null)
                    {
                        return;
                    }

                    ViewModelImagingLayerDragObject dragObject = (ViewModelImagingLayerDragObject)e.Data.GetData("stackPanelDragItem");
                    ViewModelImagingLayer           model      = control.DataContext as ViewModelImagingLayer;
                    if (dragObject.ViewModel != model)
                    {
                        control.SetCurrentValue(BackgroundProperty, new SolidColorBrush(Color.FromRgb(100, 100, 100)));
                        _isDragging = true;
                    }
                }
            }
            catch { }
        }
Exemplo n.º 2
0
 private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue == null)
     {
         this.Visibility = System.Windows.Visibility.Collapsed;
     }
     else
     {
         ViewModelImagingLayer dc = this.DataContext as ViewModelImagingLayer;
         if (dc != null)
         {
             if (dc.ImagingComponent.Visible)
             {
                 this.Visibility = System.Windows.Visibility.Visible;
             }
             else
             {
                 this.Visibility = System.Windows.Visibility.Collapsed;
             }
         }
         else
         {
             this.Visibility = System.Windows.Visibility.Collapsed;
         }
     }
     refreshRows();
 }
        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 { }
        }
Exemplo n.º 4
0
        private void refreshRows()
        {
            ViewModelImagingLayer dc = this.DataContext as ViewModelImagingLayer;

            if (dc != null)
            {
                if (LayoutRoot.ActualHeight == 0)
                {
                    return;
                }
                double rest = LayoutRoot.ActualHeight - 150;
                if (rest < 0)
                {
                    rest = 0;
                }
                if (dc.ImagingComponent.LogarithmicScaling)
                {
                    double newH;

                    newH = 0.05094287 * rest - 4.5;
                    if (newH < 0)
                    {
                        newH = 0;
                    }
                    gridRow1.Height = new GridLength(newH, GridUnitType.Pixel);

                    gridRow2.Height = new GridLength(0.072653723 * rest + 4.5, GridUnitType.Pixel);

                    gridRow3.Height = new GridLength(0.12360743 * rest + 4.5, GridUnitType.Pixel);

                    newH = 0.752795977 * rest - 4.5;
                    if (newH < 0)
                    {
                        newH = 0;
                    }
                    gridRow4.Height = new GridLength(newH, GridUnitType.Pixel);
                    layerNameText.SetCurrentValue(Grid.RowProperty, 7);
                }
                else
                {
                    double mean      = rest / 4.0;
                    double corrected = (mean - 4.5) < 0 ? 0 : (mean - 4.5);
                    gridRow1.Height = new GridLength(corrected, GridUnitType.Pixel);
                    gridRow2.Height = new GridLength(mean + 4.5, GridUnitType.Pixel);
                    gridRow3.Height = new GridLength(mean + 4.5, GridUnitType.Pixel);
                    gridRow4.Height = new GridLength(corrected, GridUnitType.Pixel);
                }
            }
        }
 public ViewModelImagingLayerDragObject(ViewModelImagingLayer vm, double width)
 {
     ViewModel = vm;
     Width     = width;
 }
        private void UserControl_DragOver(object sender, DragEventArgs e)
        {
            try
            {
                if (!_isDragging)
                {
                    return;
                }

                if (e.Data.GetDataPresent("stackPanelDragItem"))
                {
                    ViewForegroundControlHeader control = sender as ViewForegroundControlHeader;
                    if (control == null)
                    {
                        return;
                    }
                    else if (control.DataContext == null)
                    {
                        return;
                    }

                    ViewModelImagingLayer model = control.DataContext as ViewModelImagingLayer;

                    ViewModelImagingLayerDragObject dragObject = (ViewModelImagingLayerDragObject)e.Data.GetData("stackPanelDragItem");

                    if (dragObject.ViewModel != model)
                    {
                        if (model == null)
                        {
                            return;
                        }
                        ViewModelImagingComponent stableComponent = model.ImagingComponent;

                        int movingIndex = stableComponent.ImageProperties.DragComponentIndex;
                        int stableIndex = stableComponent.ParentListIndex;

                        if (movingIndex == stableIndex)
                        {
                            return;
                        }

                        if (Math.Abs(movingIndex - stableIndex) == 1)
                        {
                            Point delta = e.GetPosition(control);
                            if (movingIndex < stableIndex)
                            {
                                if (delta.X < 20)
                                {
                                    return;
                                }
                            }
                            else
                            {
                                if (delta.X > control.ActualWidth - 20)
                                {
                                    return;
                                }
                            }

                            double deadZone = control.ActualWidth - dragObject.Width;
                            if (deadZone > 0)
                            {
                                if (movingIndex < stableIndex)
                                {
                                    if (delta.X <= deadZone)
                                    {
                                        return;
                                    }
                                }
                                else if (movingIndex > stableIndex)
                                {
                                    if (delta.X >= dragObject.Width)
                                    {
                                        return;
                                    }
                                }
                            }
                        }

                        stableComponent.MoveRelativeComponent(stableComponent);
                        e.Handled = true;
                    }
                }
            }
            catch { }
        }