Ejemplo n.º 1
0
        private void OnMoveThumbDragDelta(object sender, DragDeltaEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null)
            {
                if (window.WindowState == WindowState.Maximized)
                {
                    window.Normalize();
                }

                if (window.WindowState != WindowState.Minimized)
                {
                    window.LastLeft = Canvas.GetLeft(window);
                    window.LastTop  = Canvas.GetTop(window);


                    var candidateLeft = window.LastLeft + e.HorizontalChange;
                    var candidateTop  = window.LastTop + e.VerticalChange;

                    Canvas.SetLeft(window, Math.Min(Math.Max(0, candidateLeft), window.Container.ActualWidth - 25));
                    Canvas.SetTop(window, Math.Min(Math.Max(0, candidateTop), window.Container.ActualHeight - 25));
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null && window.Container != null)
            {
                switch (window.WindowState)
                {
                case WindowState.Maximized:
                    window.Normalize();
                    break;

                case WindowState.Normal:
                    window.Maximize();
                    break;

                case WindowState.Minimized:
                    window.Normalize();
                    break;

                default:
                    throw new InvalidOperationException("Unsupported WindowsState mode");
                }
            }

            e.Handled = true;
        }
Ejemplo n.º 3
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null)
            {
                window.DoFocus(e);
            }

            base.OnMouseDown(e);
        }
Ejemplo n.º 4
0
        protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
        {
            base.OnLostKeyboardFocus(e);
            FrameworkElement parent = VisualTreeExtension.FindMdiWindow(e.NewFocus as FrameworkElement);

            if ((e.NewFocus is MdiWindow && !Equals(e.NewFocus, this)) || (parent != null && !Equals(parent, this)))
            {
                IsSelected = false;
                Panel.SetZIndex(this, 0);
                var newWindow = (e.NewFocus is MdiWindow) ? (e.NewFocus as MdiWindow) : (parent as MdiWindow);
                Container.SetValue(MdiContainer.SelectedItemProperty, newWindow.DataContext);
                newWindow.IsSelected = true;
            }
        }
Ejemplo n.º 5
0
        private void OnResizing(object sender, DragDeltaEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null)
            {
                if (window.IsFocused == false)
                {
                    window.Focus();
                }

                window.Height = window.ActualHeight;
                window.Width  = window.ActualWidth;

                switch (VerticalAlignment)
                {
                case VerticalAlignment.Bottom:
                    var deltaVertical = Math.Min(-e.VerticalChange, window.ActualHeight - window.MinHeight);
                    window.Height -= deltaVertical;
                    break;

                case VerticalAlignment.Top:
                    deltaVertical = Math.Min(e.VerticalChange, window.ActualHeight - window.MinHeight);
                    Canvas.SetTop(window, Canvas.GetTop(window) + deltaVertical);
                    window.Height -= deltaVertical;
                    break;
                }

                switch (HorizontalAlignment)
                {
                case HorizontalAlignment.Left:
                    var deltaHorizontal = Math.Min(e.HorizontalChange, window.ActualWidth - window.MinWidth);
                    Canvas.SetLeft(window, Canvas.GetLeft(window) + deltaHorizontal);
                    window.Width -= deltaHorizontal;
                    break;

                case HorizontalAlignment.Right:
                    deltaHorizontal = Math.Min(-e.HorizontalChange, window.ActualWidth - window.MinWidth);
                    window.Width   -= deltaHorizontal;
                    break;
                }
                window.Container.InvalidateSize();
            }

            e.Handled = true;
        }
Ejemplo n.º 6
0
        private void OnMoveThumbDragDelta(object sender, DragDeltaEventArgs e)
        {
            var window = VisualTreeExtension.FindMdiWindow(this);

            if (window != null)
            {
                if (window.WindowState == WindowState.Maximized)
                {
                    return;
                }

                Canvas.SetLeft(window, Math.Max(0, Canvas.GetLeft(window) + e.HorizontalChange));
                Canvas.SetTop(window, Math.Max(0, Canvas.GetTop(window) + e.VerticalChange));

                window.Container.InvalidateSize();
            }
        }