拖动WPF弹出式菜单控件

编程入门 行业动态 更新时间:2024-10-24 20:12:25
本文介绍了拖动WPF弹出式菜单控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在WPF弹出式菜单控件是好的,但在我看来比较有限。有没有办法来拖弹出时左右被打开(如用DragMove(窗口)的方法)?

the WPF Popup control is nice, but somewhat limited in my opinion. is there a way to "drag" a popup around when it is opened (like with the DragMove() method of windows)?

可以这样没有大的问题做或做我必须写一个代替自己弹出类? 谢谢

can this be done without big problems or do i have to write a substitute for the popup class myself? thanks

推荐答案

下面是一个使用拇指一个简单的解决方案。

Here's a simple solution using a Thumb.

  • 在弹出的子类在XAML和codebehind
  • 添加一个拇指宽/高设置为0(这也可以在XAML中完成)
  • 在倾听,在弹出的MouseDown事件,提高同一事件上的拇指
  • 在DragDelta移动弹出

XAML:

<Popup x:Class="PopupTest.DraggablePopup" ...> <Canvas x:Name="ContentCanvas"> </Canvas> </Popup>

C#:

public partial class DraggablePopup : Popup { public DraggablePopup() { var thumb = new Thumb { Width = 0, Height = 0, }; ContentCanvas.Children.Add(thumb); MouseDown += (sender, e) => { thumb.RaiseEvent(e); }; thumb.DragDelta += (sender, e) => { HorizontalOffset += e.HorizontalChange; VerticalOffset += e.VerticalChange; }; } }

更多推荐

拖动WPF弹出式菜单控件

本文发布于:2023-08-06 04:44:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出式   拖动   控件   菜单   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!