Пример #1
0
 private void MainWindow_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     Mouse.Capture(null);
 }
Пример #2
0
 private void OnMouseUp(object sender, MouseEventArgs e)
 {
     Mouse.Capture(EventSource, CaptureMode.None);
 }
Пример #3
0
 /// <summary>
 ///     Captures the mouse to this element.
 /// </summary>
 public bool CaptureMouse()
 {
     return(Mouse.Capture(this));
 }
Пример #4
0
        /// <summary>
        /// Handles the mouse button being released over a row header.
        /// </summary>
        /// <param name="state">The thread initialization parameter.</param>
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            // This gets the location of the mouse in document coordinates.
            Point mouseLocation = e.GetPosition(this);

            // Evaluate the state of the keyboard.  Key combinations involving the shift and control keys will alter the areas that
            // are selected.
            bool isShiftKeyPressed   = ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift);
            bool isControlKeyPressed = ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control);

            // The target row for any movement operations is the last row selected.
            ReportRow anchorRow = this.ReportGrid.Rows.FindRowAt(this.anchorPoint.Y);

            // The mouse state indications what action should be taken when the mouse button is released.
            switch (this.mouseState)
            {
            case MouseState.ResizingRow:

                // At the conclusion of the resizing operation a decision is made to remove or change the width of a row.  If
                // the size is reduced to zero (or less), this gesture is taken as a command to remove the row.  Any positive
                // value for a width will result in a row change command.
                double rowHeight = anchorRow.Height + (mouseLocation.Y - this.anchorPoint.Y);
                rowHeight = rowHeight < 0.0 ? 0.0 : rowHeight;
                if (this.ResizeMouseMove != null)
                {
                    this.ResizeMouseMove(this, new ResizeRowEventArgs(anchorRow, rowHeight, true));
                }

                // Note - this is where the logic should go for removing or resizing a row.  It should probably bubble up through
                // the Report and be handled by some higher logic that determins if removing or resizing a row is a legal action.
                // Currently it is not supported.

                // This will hide the popup until it is needed again.
                this.rowHeightPopup.IsOpen = false;

                // This is a momentary button: the column heading will loose the selection state when the button is released.
                foreach (ReportCell reportCell in this.headerCells)
                {
                    reportCell.IsSelected = false;
                }

                break;

            case MouseState.DraggingRow:

                // The action taken when the dragging operation is complete depends on whether a valid destination is selected or
                // whether the row is meant to be deleted.
                switch (this.destinationState)
                {
                case DropAction.Select:

                    // This will move the row from its current location to the desired location.
                    if (this.destinationPopup.Visibility == Visibility.Visible)
                    {
                        // TODO - This should generate an event to move a row from one place to another.
                    }

                    break;

                case DropAction.Delete:

                    // This will delete the row from the view.
                    this.ReportGrid.Rows.Remove(anchorRow);

                    break;
                }

                // This is a momentary button: the column heading will loose the selection state when the button is released.
                foreach (ReportCell reportCell in this.headerCells)
                {
                    reportCell.IsSelected = false;
                }

                break;
            }

            // This resets the state of the mouse for the next operation.
            this.mouseState = MouseState.ButtonUp;

            if (this.headerPopup.IsOpen)
            {
                this.headerPopup.IsOpen = false;
            }

            // Hide the destination cursor when the mouse is released.
            if (this.destinationPopup.IsOpen)
            {
                this.destinationPopup.IsOpen = false;
            }

            // Release the Hounds, errr... mouse.
            Mouse.Capture(null);
        }
Пример #5
0
 void Window_MouseUp(object sender, System.Windows.Input.MouseEventArgs e)
 {
     winDragged = false;
     Mouse.Capture(null);
 }
Пример #6
0
 protected override void OnMouseUp(MouseButtonEventArgs e)
 {
     OnMouseButton(e);
     Mouse.Capture(null);
 }
Пример #7
0
        private void SnapButton_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            Mouse.Capture(this);

            Cursor = Cursors.Cross;
        }
Пример #8
0
        //</SnippetMouseCapturSampleCaptureElement>

        //<SnippetMouseCaptureSampleUnCaptureElement>
        private void OnUnCaptureMouseRequest(object sender, RoutedEventArgs e)
        {
            // To release mouse capture, pass null to Mouse.Capture.
            Mouse.Capture(null);
        }
Пример #9
0
 private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     Mouse.Capture(this);
     _width  = ActualWidth;
     _height = ActualHeight;
 }
Пример #10
0
        /// <summary>
        ///     Reports when a combo box's popup opens.
        /// </summary>
        /// <param name="e">The event data for the <see cref="E:System.Windows.Controls.ComboBox.DropDownOpened" /> event.</param>
        protected override void OnDropDownOpened(EventArgs e)
        {
            base.OnDropDownOpened(e);

            Mouse.Capture(this, CaptureMode.SubTree);

            if (this.SelectedItem != null)
            {
                Keyboard.Focus(this.ItemContainerGenerator.ContainerFromItem(this.SelectedItem) as IInputElement);
            }

            this.focusedElement = Keyboard.FocusedElement;

            if (this.focusedElement != null)
            {
                this.focusedElement.LostKeyboardFocus += this.OnFocusedElementLostKeyboardFocus;
            }

            this.canSizeY = true;

            this.galleryPanel.Width  = double.NaN;
            this.scrollViewer.Height = double.NaN;

            var popupChild  = this.DropDownPopup.Child as FrameworkElement;
            var heightDelta = popupChild.DesiredSize.Height - this.scrollViewer.DesiredSize.Height;

            var initialHeight = Math.Min(RibbonControl.GetControlWorkArea(this).Height * 2 / 3, this.MaxDropDownHeight);

            if (double.IsNaN(this.DropDownHeight) == false)
            {
                initialHeight = Math.Min(this.DropDownHeight, this.MaxDropDownHeight);
            }

            if (this.scrollViewer.DesiredSize.Height > initialHeight)
            {
                this.scrollViewer.Height = initialHeight;
            }
            else
            {
                initialHeight = this.scrollViewer.DesiredSize.Height;
            }

            var monitor = RibbonControl.GetControlMonitor(this);
            var delta   = monitor.Bottom - this.PointToScreen(new Point()).Y - this.ActualHeight - initialHeight - heightDelta;

            if (delta >= 0)
            {
                this.ShowPopupOnTop = false;
            }
            else
            {
                var deltaTop = this.PointToScreen(new Point()).Y - initialHeight - heightDelta - monitor.Top;

                if (deltaTop > delta)
                {
                    this.ShowPopupOnTop = true;
                }
                else
                {
                    this.ShowPopupOnTop = false;
                }

                if (deltaTop < 0)
                {
                    delta = Math.Max(Math.Abs(delta), Math.Abs(deltaTop));

                    if (delta > this.galleryPanel.GetItemSize().Height)
                    {
                        this.scrollViewer.Height = delta;
                    }
                    else
                    {
                        this.canSizeY            = false;
                        this.scrollViewer.Height = this.galleryPanel.GetItemSize().Height;
                    }
                }
            }

            popupChild.UpdateLayout();
        }
Пример #11
0
 //<SnippetMouseCapturSampleCaptureElement>
 private void OnCaptureMouseRequest(object sender, RoutedEventArgs e)
 {
     Mouse.Capture(_elementToCapture);
 }
Пример #12
0
 // клавиша отпущена - завершаем процесс
 void OnMouseUp(object sender, MouseButtonEventArgs e)
 {
     FinishDrag(sender, e);
     Mouse.Capture(null);
 }
Пример #13
0
 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
 {
     base.OnMouseLeftButtonDown(e);
     Mouse.Capture(this);
 }
Пример #14
0
 private void OnMouseDown(object sender, MouseEventArgs e)
 {
     Mouse.Capture(EventSource, CaptureMode.Element);
     _previousPosition2D = e.GetPosition(EventSource);
 }
Пример #15
0
 protected void PopupMouseLeave(object sender, MouseEventArgs e)
 {
     Mouse.Capture(null);
 }
Пример #16
0
 private void OnMouseUp(object sender, MouseButtonEventArgs e)
 {
     Mouse.Capture(null);
 }
Пример #17
0
 protected override void OnMouseDown(MouseButtonEventArgs e)
 {
     Focus();
     OnMouseButton(e);
     Mouse.Capture(this);
 }
Пример #18
0
 /// <summary>
 /// Called when the TreeView popup is opened.
 /// </summary>
 protected virtual void OnTreePopupOpened()
 {
     _selectedFromTreeView = GuiTreeView.SelectedValue;
     Mouse.Capture(this, CaptureMode.SubTree);
 }
Пример #19
0
        /// <summary>
        /// Reports when a combo box's popup opens.
        /// </summary>
        /// <param name="e">The event data for the <see cref="E:System.Windows.Controls.ComboBox.DropDownOpened"/> event.</param>
        protected override void OnDropDownOpened(EventArgs e)
        {
            Focus();
            base.OnDropDownOpened(e);
            Mouse.Capture(this, CaptureMode.SubTree);
            if (SelectedItem != null)
            {
                Keyboard.Focus(ItemContainerGenerator.ContainerFromItem(SelectedItem) as IInputElement);
            }
            focusedElement = Keyboard.FocusedElement;
            focusedElement.LostKeyboardFocus += OnFocusedElementLostKeyboardFocus;

            canSizeX = true;
            canSizeY = true;

            galleryPanel.Width  = double.NaN;
            scrollViewer.Height = double.NaN;

            FrameworkElement popupChild = popup.Child as FrameworkElement;

            scrollViewer.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            popupChild.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            popup.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            double heightDelta = popupChild.DesiredSize.Height - scrollViewer.DesiredSize.Height;

            double initialHeight = Math.Min(RibbonControl.GetControlWorkArea(this).Height * 2 / 3, MaxDropDownHeight);

            if (!double.IsNaN(DropDownHeight))
            {
                initialHeight = Math.Min(DropDownHeight, MaxDropDownHeight);
            }
            if (scrollViewer.DesiredSize.Height > initialHeight)
            {
                scrollViewer.Height = initialHeight;
            }
            else
            {
                initialHeight = scrollViewer.DesiredSize.Height;
            }

            Rect   monitor = RibbonControl.GetControlMonitor(this);
            double delta   = monitor.Bottom - this.PointToScreen(new Point()).Y - ActualHeight - initialHeight - heightDelta;

            if (delta >= 0)
            {
                ShowPopupOnTop = false;
            }
            else
            {
                double deltaTop = this.PointToScreen(new Point()).Y - initialHeight - heightDelta - monitor.Top;
                if (deltaTop > delta)
                {
                    ShowPopupOnTop = true;
                }
                else
                {
                    ShowPopupOnTop = false;
                }

                if (deltaTop < 0)
                {
                    delta = Math.Max(Math.Abs(delta), Math.Abs(deltaTop));
                    if (delta > galleryPanel.GetItemSize().Height)
                    {
                        scrollViewer.Height = delta;
                    }
                    else
                    {
                        canSizeY            = false;
                        scrollViewer.Height = galleryPanel.GetItemSize().Height;
                    }
                }
            }
            popupChild.UpdateLayout();
        }
Пример #20
0
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     Mouse.Capture(this, CaptureMode.SubTree);
     //Mouse.AddLostMouseCaptureHandler(this, OnMouseCaptureLost); // Inputlara girince Mouse Capture Beklemeye Geçiyor. Bu olayı yakalayıp tekrardan Mouse capture açıyorum
     AddHandler();
 }
Пример #21
0
        /// <summary>
        /// Handles the mouse button being pressed.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            // The sort order is maintained in this structure.
            this.sortOrder = new List <SortItem>();

            // This gets the location of the mouse in document coordinates.
            Mouse.Capture(this);

            // This state variable will control how the 'Mouse Move' and 'Mouse Up' event handlers interpret the user action.  The
            // 'selectedRow' field is used as the starting point for any drag-and-drop type of operation.
            this.mouseState = MouseState.ButtonDown;

            // Evaluate the state of the keyboard.  Key combinations involving the shift and control keys will alter the areas that
            // are selected.
            bool isShiftKeyPressed   = ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift);
            bool isControlKeyPressed = ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control);

            // This will use the current position for an anchor unless the shift key is pressed.
            this.mouseDownLocation = e.GetPosition(this);
            if (!isShiftKeyPressed)
            {
                this.anchorPoint = this.mouseDownLocation;
            }

            // The mouse indicates which column has been selected and the anchor indicates the starting point of the selection in
            // an extended selection operation.
            ReportRow selectedRow = this.ReportGrid.Rows.FindRowAt(this.mouseDownLocation.Y);
            ReportRow anchorRow   = this.ReportGrid.Rows.FindRowAt(this.anchorPoint.Y);

            Point mouseDownLocation = e.GetPosition(this);

            if (!isShiftKeyPressed)
            {
                IInputElement    iInputElement    = this.InputHitTest(mouseDownLocation);
                DependencyObject dependencyObject = iInputElement as DependencyObject;
                while (dependencyObject != null)
                {
                    if (DynamicReport.GetCell(dependencyObject) != null)
                    {
                        Keyboard.Focus(dependencyObject as IInputElement);
                        break;
                    }
                    dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
                }
            }

            // Every cell that appears in the header canvas is considered part of the selectable header.  This will collect all the
            // selected cells in a list while creating a rectangle that is the union of all those selected cells.
            this.headerCells.Clear();
            foreach (ReportColumn reportColumn in this.ReportGrid.Columns)
            {
                ReportCell reportCell = selectedRow[reportColumn];
                if (reportColumn.Left < this.ActualWidth)
                {
                    this.headerCells.Add(reportCell);
                }
            }

            // If a row is selected then the position and movement of the mouse will suggest one of several gestures that need
            // to be interpreted: is a row being moved, is it being resized, is it being deleted or selected?  The code below
            // will begin to interpret the input gesture.
            if (selectedRow != null)
            {
                // The header has two modes: when the headers are frozen, only selection operations are enabled with the mouse.
                // When not frozen, the rows can be moved, resized, resorted and removed.
                if (this.IsHeaderFrozen)
                {
                    // The shift and control key extend the selection operation in the same way as Microsoft Excel.
                    if (isShiftKeyPressed || isControlKeyPressed)
                    {
                        // When the shift key is pressed during row selection, every row between the last row selected
                        // and the current row is selected.
                        if (isShiftKeyPressed)
                        {
                            // In the unlikely event that the shift key was down during the setting of the anchor point, this will
                            // create a dummy entry in the list of selected row ranges.
                            if (this.selectedRanges.Count == 0)
                            {
                                List <ReportRow> reportRows = new List <ReportRow>();
                                reportRows.Add(selectedRow);
                                this.selectedRanges.Add(reportRows);
                            }

                            // The most recent range will be replaced with a new range when the mouse is dragged around the row
                            // headers.  This has the effect of clearing the rows that are no longer selected and selecting only
                            // the rows between the anchor and the currently selected row.
                            List <ReportRow> lastRange = this.selectedRanges[this.selectedRanges.Count - 1];

                            // This will select each row between the last selected row and the one just selected.  Note that the
                            // list of rows is distinct, so duplicate rows are ignored.
                            ReportRow firstRow  = anchorRow.Top < selectedRow.Top ? anchorRow : selectedRow;
                            ReportRow secondRow = anchorRow.Top < selectedRow.Top ? selectedRow : anchorRow;
                            lastRange.Clear();
                            foreach (ReportRow reportRow in this.ReportGrid.Rows)
                            {
                                if (firstRow.Top <= reportRow.Top && reportRow.Top <= secondRow.Top)
                                {
                                    lastRange.Add(reportRow);
                                }
                            }
                        }

                        // When the control key is pressed a single row is added to the range of rows selected.
                        if (isControlKeyPressed)
                        {
                            // This removes any previous instance of this row in the selection.
                            foreach (List <ReportRow> rowRange in this.selectedRanges)
                            {
                                if (rowRange.Contains(selectedRow))
                                {
                                    rowRange.Remove(selectedRow);
                                }
                            }

                            // The row is added (or re-added) at the start of the range of selected rows.
                            List <ReportRow> reportRows = new List <ReportRow>();
                            reportRows.Add(selectedRow);
                            this.selectedRanges.Add(reportRows);
                        }
                    }
                    else
                    {
                        // The row is added at the start of a new range of selected rows.
                        List <ReportRow> reportRows = new List <ReportRow>();

                        // The if condition below fixes issue that allows the right click to not clear the selected rows.
                        // Hence it allows every other condition to clear the state.
                        if (e.RightButton != MouseButtonState.Pressed)
                        {
                            // A simple selection that doesn't involve the modifier keys will clear out any previously selected ranges.
                            this.selectedRanges.Clear();
                        }
                        else
                        {
                            // This removes any previous instance of this row in the selection.
                            foreach (List <ReportRow> rowRange in this.selectedRanges)
                            {
                                if (rowRange.Contains(selectedRow))
                                {
                                    rowRange.Remove(selectedRow);
                                }
                            }
                        }

                        reportRows.Add(selectedRow);
                        this.selectedRanges.Add(reportRows);
                    }

                    // This will select all the rows in the selected ranges of rows and remove the selection from all the
                    // rest of the cells.
                    SelectRows();

                    // This instructs the event handlers how the mouse movement is to be interpreted.
                    this.mouseState = MouseState.Selecting;
                }
                else
                {
                    // The top mouse button can either select the row or begin a resizing operation.  This will perform a 'Hit
                    // Test' to see which operation should be performed.
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        // This is a 'Hit Test' for the bottom edge of the row header tile to see if the user is trying to change
                        // the size of the row.  If the mouse is close to the bottom edge, then the drag operation to change the
                        // size of the tile is begun.
                        if (selectedRow.Bottom - DynamicReport.splitBorder <= this.mouseDownLocation.Y &&
                            this.mouseDownLocation.Y < selectedRow.Bottom)
                        {
                            this.resizeStart    = selectedRow.Bottom;
                            this.mouseState     = MouseState.ResizingRow;
                            this.destinationRow = null;
                        }
                        else
                        {
                            // This is a 'Hit Test' for the top edge of the row header tile to see if the user is trying to change
                            // the size of the row.  Note that because the top edge really belongs to the previous row header when
                            // resizing, that the previous row is selected for the operation.
                            if (selectedRow.Top <= this.mouseDownLocation.Y &&
                                this.mouseDownLocation.Y < selectedRow.Top + DynamicReport.splitBorder)
                            {
                                this.resizeStart = selectedRow.Top;
                                this.mouseState  = MouseState.ResizingRow;
                                foreach (ReportRow reportRow in this.ReportGrid.Rows)
                                {
                                    if (reportRow.Bottom == selectedRow.Top)
                                    {
                                        selectedRow = reportRow;
                                    }
                                }
                                this.destinationRow = null;
                            }
                        }
                    }

                    // At this point, a resizing operation has been selected from the input gesture of the mouse.
                    if (this.mouseState == MouseState.ResizingRow)
                    {
                        // The parent window will watch for this event to tell it how to draw the row width indicator lines. The
                        // dimension and location of those lines are outside of this window and must be handled by the parent.
                        if (this.ResizeMouseMove != null)
                        {
                            this.ResizeMouseMove(this, new ResizeRowEventArgs(selectedRow, selectedRow.Height,
                                                                              false));
                        }

                        // This window provides quantitative feedback for the new width of the row.  The offsets were arrived at
                        // empirically from reverse engineering Excel.
                        this.rowHeightPopup.VerticalOffset = this.mouseDownLocation.Y - 2.0;
                        this.rowHeightPopup.Content        = selectedRow.Height;
                        this.rowHeightPopup.IsOpen         = true;
                    }
                    else
                    {
                        // This will select the button momentarily for drag-and-drop and sorting operations.
                        foreach (ReportCell reportCell in this.headerCells)
                        {
                            reportCell.IsSelected = true;
                        }
                    }
                }
            }
        }
Пример #22
0
 /// <summary>
 /// re-capturing when lost Mouse.Capture handled
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnMouseCaptureLost(object sender, MouseEventArgs e)
 {
     Mouse.Capture(this, CaptureMode.SubTree);
 }
Пример #23
0
        private void chooseImage_Button_Click(object sender, RoutedEventArgs e)
        {
            var screen = new OpenFileDialog();

            screen.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";

            if (screen.ShowDialog() == true)
            {
                restartbtn(_size);
                imgPath = screen.FileName;
                var source = new BitmapImage(new Uri(screen.FileName, UriKind.Absolute));
                //Debug.WriteLine($"{source.Width} - {source.Height}");
                newGame_image = source;

                previewImage.Width  = 350;
                previewImage.Height = 280;
                previewImage.Source = source;

                Canvas.SetLeft(previewImage, 400);
                Canvas.SetTop(previewImage, startX);

                // Bat dau cat thanh 9 manh
                try
                {
                    for (int i = 0; i < _size; i++)
                    {
                        for (int j = 0; j < _size; j++)
                        {
                            if (!((i == _size - 1) && (j == _size - 1)))
                            {
                                if (!((i == _size - 1) && (j == _size - 1)))
                                {
                                    int h, w;
                                    if ((int)source.Height < (int)source.Width)
                                    {
                                        h = (int)source.Height / _size;
                                        w = (int)source.Height / _size;
                                    }
                                    else
                                    {
                                        h = (int)source.Width / _size;
                                        w = (int)source.Width / _size;
                                    }
                                    //MessageBox.Show($"{h}-{w} {source.Width}-{source.Height}");

                                    //Debug.WriteLine($"Len = {len}");
                                    var rect       = new Int32Rect(i * w, j * h, w, h);
                                    var cropBitmap = new CroppedBitmap(source, rect);
                                    var cropImage  = new Image();
                                    cropImage.Stretch   = Stretch.Fill;
                                    cropImage.Width     = width;
                                    cropImage.Height    = height;
                                    cropImage.Source    = cropBitmap;
                                    image_cropped[i, j] = cropImage;
                                    canvas.Children.Add(cropImage);
                                    Canvas.SetLeft(cropImage, startX + i * (width + 2));
                                    Canvas.SetTop(cropImage, startY + j * (height + 2));

                                    cropImage.MouseLeftButtonDown      += CropImage_MouseLeftButtonDown;
                                    cropImage.PreviewMouseLeftButtonUp += CropImage_PreviewMouseLeftButtonUp;
                                    Mouse.Capture(cropImage);
                                    cropImage.Tag = new Tuple <int, int>(i, j);
                                    //cropImage.MouseLeftButtonUp
                                    _imageCheck[i, j] = _size * i + j;
                                }
                            }
                        }
                    }
                    _canplay = true;
                    //the empty image is marked -1 value
                    _imageCheck[_size - 1, _size - 1] = -1;
                }
                catch
                {
                    MessageBox.Show("Please choose other image.\nThis image cant crop", "Can't crop image");
                    _canplay = false;
                }
            }
        }
Пример #24
0
 private void openGlCtrl_MouseUp(object sender, MouseButtonEventArgs e)
 {
     Debug.WriteLine("ButtonLMBUp");
     _ImageDrag = false;
     Mouse.Capture(null);
 }
Пример #25
0
        protected virtual void OnIsOpenChanged(bool oldIsOpen, bool newIsOpen)
        {
            var animationType = Parameters.Animation.GetType(this);

            if (newIsOpen && !oldIsOpen)
            {
                IsOpening = true;

                OnOpening(new RoutedEventArgs(OpeningEvent, this));

                if (animationType == Animation.None)
                {
                    Mouse.Capture(this, CaptureMode.SubTree);

                    _isOpen = true;
                    InvalidateArrange();

                    OnOpened(new RoutedEventArgs(OpenedEvent, this));

                    IsOpening = false;
                }
                else
                {
                    var storyboard = new Storyboard
                    {
                        FillBehavior = FillBehavior.Stop
                    };

                    Timeline animation;
                    switch (animationType)
                    {
                    case Animation.Fade:
                        animation = new DoubleAnimation(0d, 1d, Parameters.Animation.GetMinimumDuration(this));

                        Storyboard.SetTarget(animation, this);
                        Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));

                        // NOTE: Lack of contracts
                        Contract.Assume(storyboard.Children != null);
                        storyboard.Children.Add(animation);
                        break;

                    case Animation.Slide:
                        animation = new DoubleAnimation(0d, DesiredSize.Height, Parameters.Animation.GetMinimumDuration(this));

                        Storyboard.SetTarget(animation, this);
                        Storyboard.SetTargetProperty(animation, new PropertyPath("Height"));

                        // NOTE: Lack of contracts
                        Contract.Assume(storyboard.Children != null);
                        storyboard.Children.Add(animation);
                        break;
                    }

                    storyboard.Completed += (sender, e) =>
                    {
                        storyboard.Stop(this);
                        storyboard.Remove(this);

                        OnOpened(new RoutedEventArgs(OpenedEvent, this));

                        IsOpening = false;
                    };

                    if (!StaysOpen)
                    {
                        Mouse.Capture(this, CaptureMode.SubTree);
                    }

                    storyboard.AsFrozen().Begin(this, true);

                    _isOpen = true;
                    InvalidateArrange();
                }
            }
            if (!newIsOpen && oldIsOpen)
            {
                IsClosing = true;

                OnClosing(new RoutedEventArgs(ClosingEvent, this));

                if (animationType == Animation.None)
                {
                    Mouse.Capture(null);

                    _isOpen = false;
                    InvalidateArrange();

                    OnClosed(new RoutedEventArgs(ClosedEvent, this));

                    IsClosing = false;
                }
                else
                {
                    var storyboard = new Storyboard
                    {
                        FillBehavior = FillBehavior.Stop
                    };

                    Timeline animation;
                    switch (animationType)
                    {
                    case Animation.Fade:
                        animation = new DoubleAnimation(1d, 0d, Parameters.Animation.GetMinimumDuration(this));

                        Storyboard.SetTarget(animation, this);
                        Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));

                        // NOTE: Lack of contracts
                        Contract.Assume(storyboard.Children != null);
                        storyboard.Children.Add(animation);
                        break;

                    case Animation.Slide:
                        animation = new DoubleAnimation(DesiredSize.Height, 0d, Parameters.Animation.GetMinimumDuration(this));

                        Storyboard.SetTarget(animation, this);
                        Storyboard.SetTargetProperty(animation, new PropertyPath("Height"));

                        // NOTE: Lack of contracts
                        Contract.Assume(storyboard.Children != null);
                        storyboard.Children.Add(animation);
                        break;
                    }

                    storyboard.Completed += (sender, e) =>
                    {
                        storyboard.Stop(this);
                        storyboard.Remove(this);

                        if (!StaysOpen)
                        {
                            Mouse.Capture(null);
                        }

                        _isOpen = false;
                        InvalidateArrange();

                        OnClosed(new RoutedEventArgs(ClosedEvent, this));

                        IsClosing = false;
                    };

                    storyboard.AsFrozen().Begin(this, true);
                }
            }
        }
Пример #26
0
 private void image1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     Debug.WriteLine("ButtonLMBUp");
     _ImageDrag = false;
     Mouse.Capture(null);
 }
        internal void ChangeStylusCapture(IInputElement stylusCapture, CaptureMode captureMode, int timestamp)
        {
            // if the capture changed...
            if (stylusCapture != _stylusCapture)
            {
                // Actually change the capture first.  Invalidate the properties,
                // and then send the events.
                IInputElement oldStylusCapture = _stylusCapture;

                _stylusCapture = stylusCapture;
                _captureMode   = captureMode;

                // We also need to figure out ahead of time if any plugincollections on this captured element (or a parent)
                // for the penthread hittesting code.
                _stylusCapturePlugInCollection = null;

                if (stylusCapture != null)
                {
                    UIElement uiElement = InputElement.GetContainingUIElement(stylusCapture as DependencyObject) as UIElement;
                    if (uiElement != null)
                    {
                        PresentationSource source = PresentationSource.CriticalFromVisual(uiElement as Visual);

                        if (source != null)
                        {
                            PointerStylusPlugInManager manager;

                            if (_pointerLogic.PlugInManagers.TryGetValue(source, out manager))
                            {
                                _stylusCapturePlugInCollection = manager.FindPlugInCollection(uiElement);
                            }
                        }
                    }
                }

                _pointerLogic.UpdateStylusCapture(this, oldStylusCapture, _stylusCapture, timestamp);

                // Send the LostStylusCapture and GotStylusCapture events.
                if (oldStylusCapture != null)
                {
                    StylusEventArgs lostCapture = new StylusEventArgs(StylusDevice, timestamp);
                    lostCapture.RoutedEvent = Stylus.LostStylusCaptureEvent;
                    lostCapture.Source      = oldStylusCapture;
                    InputManager.UnsecureCurrent.ProcessInput(lostCapture);
                }
                if (_stylusCapture != null)
                {
                    StylusEventArgs gotCapture = new StylusEventArgs(StylusDevice, timestamp);
                    gotCapture.RoutedEvent = Stylus.GotStylusCaptureEvent;
                    gotCapture.Source      = _stylusCapture;
                    InputManager.UnsecureCurrent.ProcessInput(gotCapture);
                }

                // Now update the stylus over state (only if this is the current stylus and
                // it is inrange).
                if (_pointerLogic.CurrentStylusDevice == this || InRange)
                {
                    if (_stylusCapture != null)
                    {
                        IInputElement inputElementHit = _stylusCapture;

                        // See if we need to update over for subtree mode.
                        if (CapturedMode == CaptureMode.SubTree && _inputSource != null && _inputSource.Value != null)
                        {
                            Point pt = _pointerLogic.DeviceUnitsFromMeasureUnits(_inputSource.Value, GetPosition(null));
                            inputElementHit = FindTarget(_inputSource.Value, pt);
                        }

                        ChangeStylusOver(inputElementHit);
                    }
                    else
                    {
                        // Only try to update over if we have a valid input source.
                        if (_inputSource != null && _inputSource.Value != null)
                        {
                            Point pt = GetPosition(null);                                           // relative to window (root element)
                            pt = _pointerLogic.DeviceUnitsFromMeasureUnits(_inputSource.Value, pt); // change back to device coords.
                            IInputElement currentOver = Input.StylusDevice.GlobalHitTest(_inputSource.Value, pt);
                            ChangeStylusOver(currentOver);
                        }
                    }
                }

                // For Mouse StylusDevice we want to make sure Mouse capture is set up the same.
                if (Mouse.Captured != _stylusCapture || Mouse.CapturedMode != _captureMode)
                {
                    Mouse.Capture(_stylusCapture, _captureMode);
                }
            }
        }
Пример #28
0
 protected void PopupMouseEnter(object sender, MouseEventArgs e)
 {
     Focus();
     Mouse.Capture(this);
 }
Пример #29
0
 /// <summary>
 ///     Releases the mouse capture.
 /// </summary>
 public void ReleaseMouseCapture()
 {
     Mouse.Capture(null);
 }
Пример #30
0
 // handles popup opening
 private void OnRibbonGroupBoxPopupOpening()
 {
     //IsHitTestVisible = false;
     Mouse.Capture(this, CaptureMode.SubTree);
 }