当前位置: 首页>>代码示例>>C#>>正文


C# UIElement.ReleaseMouseCapture方法代码示例

本文整理汇总了C#中System.Windows.UIElement.ReleaseMouseCapture方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.ReleaseMouseCapture方法的具体用法?C# UIElement.ReleaseMouseCapture怎么用?C# UIElement.ReleaseMouseCapture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.UIElement的用法示例。


在下文中一共展示了UIElement.ReleaseMouseCapture方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddDragHandler

        public void AddDragHandler(UIElement canvas)
        {
            MouseButtonEventHandler startDragging = null;
            startDragging = (object sender, MouseButtonEventArgs downEvent) =>
            {
                if (downEvent.ChangedButton != MouseButton.Middle)
                {
                    downEvent.Handled = false;
                    return;
                }

                downEvent.Handled = true;

                canvas.CaptureMouse();

                var dragStartPos = PointConversions.CanvasFromMouse(downEvent.MouseDevice, canvas);
                var originStartPos = _origin.Point;

                MouseEventHandler MiddleDragListener = (object o, MouseEventArgs moveEvent) =>
                {
                    var mouse_pos = PointConversions.CanvasFromMouse(moveEvent.MouseDevice, canvas);

                    _origin.Point = new CanvasPosition
                    {
                        X = originStartPos.X + (mouse_pos.X - dragStartPos.X),
                        Y = originStartPos.Y + (mouse_pos.Y - dragStartPos.Y),
                    };
                };

                MouseButtonEventHandler mouseUpListener = null;
                mouseUpListener = (object bob, MouseButtonEventArgs upEvent) =>
                {
                    if (upEvent.ChangedButton != MouseButton.Middle)
                    {
                        upEvent.Handled = false;
                        return;
                    }
                    canvas.ReleaseMouseCapture();

                    upEvent.Handled = true;

                    canvas.MouseMove -= MiddleDragListener;
                    canvas.MouseUp -= mouseUpListener;
                    canvas.MouseDown += startDragging;
                };

                canvas.MouseMove += MiddleDragListener;
                canvas.MouseUp += mouseUpListener;
                canvas.MouseDown -= startDragging;
            };

            canvas.MouseDown += startDragging;
        }
开发者ID:ChaosCabbage,项目名称:plotter-service-for-visual-studio,代码行数:53,代码来源:MousePanningHandler.cs

示例2: DoDragDrop

		public void DoDragDrop(IDataObject dataObject, UIElement dragSource, bool showDragVisual, bool useVisualBrush, DragDropEffects effects)
		{
			if (!IsDragging)
			{
				_useDefaultCursor = true;
				_dragScope = Application.Current.MainWindow.Content as FrameworkElement;
				bool previousDrop = _dragScope.AllowDrop;
				_dragScope.AllowDrop = true;

				_dragScope.PreviewDragOver += DragScope_PreviewDragOver;
				_dragScope.DragOver += DragScope_DragOver;
				_dragScope.DragLeave += DragScope_DragLeave;
				_dragScope.DragEnter += DragScope_DragEnter;
				_dragScope.GiveFeedback += DragSource_GiveFeedback;
				_dragScope.QueryContinueDrag += DragScope_QueryContinueDrag;

				var _layer = AdornerLayer.GetAdornerLayer(_dragScope);
				if (showDragVisual)
				{
					_dragAdorner = new DragAdorner(_dragScope, dragSource, useVisualBrush);
					_layer.Add(_dragAdorner);
				}

				IsDragging = true;
				_dragHasLeftScope = false;
				dragSource.CaptureMouse();
				DragDropEffects de = System.Windows.DragDrop.DoDragDrop(dragSource, dataObject, effects);
				dragSource.ReleaseMouseCapture();

				if (_dragAdorner != null)
				{
					_layer.Remove(_dragAdorner);
					_dragAdorner = null;
				}
				_dragScope.AllowDrop = previousDrop;

				_dragScope.GiveFeedback -= DragSource_GiveFeedback;
				_dragScope.DragLeave -= DragScope_DragLeave;
				_dragScope.DragLeave -= DragScope_DragEnter;
				_dragScope.QueryContinueDrag -= DragScope_QueryContinueDrag;
				_dragScope.DragOver -= DragScope_DragOver;
				_dragScope.PreviewDragOver -= DragScope_PreviewDragOver;

				IsDragging = false;
			}
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:46,代码来源:DragDropService.cs

示例3: PageFlipper

        public PageFlipper(Size pageSize, UIElement hotCorner, UIElement pageHolder, FrameworkElement curlShadow, FrameworkElement dropShadow)
        {
            Contract.Requires(pageSize.IsValid());
            m_pageSize = pageSize;

            m_hotCorner = hotCorner;

            m_curlShadow = curlShadow;
            m_dropShadow = dropShadow;

            // can be null
            m_pageHolder = pageHolder;

            #region helper values
            m_pageHalfHeight = m_pageSize.Height * .5;
            m_origin = new Point(m_pageSize.Width, m_pageSize.Height / 2.0);
            m_pageDiagonal = Math.Sqrt(m_pageSize.Width * m_pageSize.Width + m_pageSize.Height * m_pageSize.Height);
            m_pointLeft = new Point(-m_pageSize.Width, m_pageHalfHeight);
            m_pointRight = new Point(m_pageSize.Width, m_pageHalfHeight);
            #endregion

            #region clips and transforms

            m_pageTransformGroup = new TransformGroup();
            m_pageTransformGroup.Children.Add(new TranslateTransform() { Y = -m_pageSize.Height });
            m_pageTransformGroup.Children.Add(m_pageRotateTransform = new RotateTransform());
            m_pageTransformGroup.Children.Add(m_pageTranslateTransform = new TranslateTransform());

            m_pageHolderClip = new RectangleGeometry() { Rect = new Rect(0, 0, m_pageSize.Width, m_pageSize.Height * 2) };
            m_nextPageClip = new RectangleGeometry() { Rect = new Rect(0, 0, m_pageSize.Width * 2, m_pageSize.Height * 2) };

            if (m_curlShadow != null)
            {
                var group = new TransformGroup();
                group.Children.Add(m_curlShadowRotate = new RotateTransform());
                group.Children.Add(m_curlShadowTranslate = new TranslateTransform());
                m_curlShadow.RenderTransform = group;

                m_curlShadow.Height = m_pageDiagonal * 1.5;
                m_curlShadowRotate.CenterX = m_curlShadow.Width;
                m_curlShadowRotate.CenterY = m_pageDiagonal;

                m_curlShadowTranslate.Y = m_pageSize.Height - m_pageDiagonal;
            }

            if (m_dropShadow != null)
            {
                //m_dropShadowBlurEffect = new BlurEffect() { Radius = 20 };
                //m_dropShadow.Effect = m_dropShadowBlurEffect;
                m_dropShadow.RenderTransform = m_pageTransformGroup;
                m_dropShadow.Width = m_pageSize.Width;
                m_dropShadow.Height = m_pageSize.Height;
            }

            #endregion

            // MOST OF THE LOADED FUNCTION IS USED TO SET LOOK UP VALUES
            // BASED ON THE pageWidth AND pageHeight INITIALLY DEFINED.
            // POSITION THE PAGE AND SPINE VISUALS ACCORDINGLY
            m_mouse.X = m_pageSize.Width - 1;
            m_mouse.Y = m_pageHalfHeight - 1;
            m_follow = m_mouse;

            #region mouse handlers

            if (m_hotCorner != null && m_pageHolder != null)
            {
                m_hotCorner.MouseMove += (sender, e) =>
                {
                    m_animating = false;
                    m_listener.StartListening();
                    Point testBounds = (Point)e.GetPosition(m_pageHolder).Subtract(m_origin);
                    if (testBounds.X > m_pageSize.Width && testBounds.Y > m_pageHalfHeight)
                    {
                        m_mouse = m_pointRight;
                    }
                    else
                    {
                        m_mouse = testBounds;
                    }
                };

                m_hotCorner.MouseLeftButtonDown += (sender, e) =>
                {
                    m_hotCorner.CaptureMouse();
                };

                m_hotCorner.MouseLeftButtonUp += (sender, e) =>
                {
                    m_listener.StartListening();
                    m_hotCorner.ReleaseMouseCapture();
                    m_mouse = (m_mouse.X < 0) ? m_pointLeft : m_pointRight;
                };

                m_hotCorner.MouseLeave += (sender, e) =>
                {
                    m_listener.StartListening();
                    m_mouse = m_pointRight;
                };
            }
//.........这里部分代码省略.........
开发者ID:edealbag,项目名称:bot,代码行数:101,代码来源:PageFlipper.cs

示例4: EndFluidDrag

        /// <summary>
        /// Handler for the event when the user stops dragging the dragElement and releases it.
        /// </summary>
        /// <param name="child">UIElement being dragged</param>
        /// <param name="position">Position where the user clicked w.r.t. the UIElement being dragged</param>
        /// <param name="positionInParent">Position where the user clicked w.r.t. the FluidWrapPanel (the parentFWPanel of the UIElement being dragged</param>
        internal void EndFluidDrag(UIElement child, Point position, Point positionInParent)
        {
            if ((child == null) || (!IsComposing))
                return;

            // Call the event handler core on the Dispatcher. (Improves efficiency!)
            Dispatcher.BeginInvoke(new Action(() =>
            {
                if ((dragElement != null) && (layoutManager != null))
                {
                    dragElement.RenderTransform = layoutManager.CreateTransform(positionInParent.X - dragStartPoint.X,
                                                                                positionInParent.Y - dragStartPoint.Y,
                                                                                DragScale,
                                                                                DragScale);

                    child.Opacity = NORMAL_OPACITY;
                    // Z-Index is set to 1 so that during the animation it does not go below other elements.
                    child.SetValue(Canvas.ZIndexProperty, Z_INDEX_INTERMEDIATE);
                    // Release the mouse capture
                    child.ReleaseMouseCapture();

                    // Reference used to set the Z-Index to 0 during the UpdateFluidLayout
                    lastDragElement = dragElement;

                    dragElement = null;
                }

                UpdateFluidLayout();
            }));
        }
开发者ID:gawallsibya,项目名称:BIT_TeamProject,代码行数:36,代码来源:FluidWrapPanel.cs

示例5: MouseUp

 public static void MouseUp(MouseButtonEventArgs e, UIElement element, IControlMouseInteraction control)
 {
     var location = e.GetPosition(element);
     var keysHeld = GetKeysHeld();
     float x = (float)location.X;
     float y = (float)location.Y;
     element.ReleaseMouseCapture();
     switch (e.ChangedButton)
     {
         case MouseButton.Left:
             control.MouseUp(x, y, MouseButtonType.Left, keysHeld);
             break;
         case MouseButton.Middle:
             control.MouseUp(x, y, MouseButtonType.Middle, keysHeld);
             break;
         case MouseButton.Right:
             control.MouseUp(x, y, MouseButtonType.Right, keysHeld);
             break;
     }
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:20,代码来源:GenericControlHelper.cs

示例6: EndFluidDragAsync

        /// <summary>
        /// Handler for the event when the user stops dragging the dragElement and releases it.
        /// </summary>
        /// <param name="child">UIElement being dragged</param>
        /// <param name="position">Position where the user clicked w.r.t. the UIElement being dragged</param>
        /// <param name="positionInParent">Position where the user clicked w.r.t. the FluidWrapPanel (the parentFWPanel of the UIElement being dragged</param>
        internal async Task EndFluidDragAsync(UIElement child, Point position, Point positionInParent)
        {
            if ((child == null) || (!IsComposing) || (_dragElement == null))
                return;

            // Call the event handler core on the Dispatcher. (Improves efficiency!)
            await Dispatcher.InvokeAsync(() =>
            {
                _dragElement.RenderTransform = CreateTransform(positionInParent.X - _dragStartPoint.X,
                                                               positionInParent.Y - _dragStartPoint.Y,
                                                               DragScale,
                                                               DragScale);

                child.Opacity = NORMAL_OPACITY;
                // Z-Index is set to 1 so that during the animation it does not go below other elements.
                child.SetValue(ZIndexProperty, Z_INDEX_INTERMEDIATE);
                // Release the mouse capture
                child.ReleaseMouseCapture();

                // Reference used to set the Z-Index to 0 during the UpdateFluidLayout
                _lastDragElement = _dragElement;

                _dragElement = null;
                _lastExchangeElement = null;

                InvalidateVisual();
            });
        }
开发者ID:IDSResearchDev,项目名称:wpfspark,代码行数:34,代码来源:FluidWrapPanel.cs


注:本文中的System.Windows.UIElement.ReleaseMouseCapture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。