本文介绍了拖动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弹出式菜单控件
发布评论