为什么要"this.DragMove()"?举行其他一些“事件"吗?尚未解决! [英] Why "this.DragMove()" hold up some of other "events"? Not Solved Yet!
问题描述
大家好,
当我使用"this.DragMove();"移动窗口WPF时方法放到桌面空间周围,它没有发生"Body_MouseLeftButtonUp"事件,为什么?
注意:主体是ModelUIElement3D,并且某些窗口属性设置为Background ="{x:Null}",AllowsTransparency ="True"和WindowStyle ="None".
Hi everybody,
When I moving my window WPF with "this.DragMove();" method into around desktop space, after it "Body_MouseLeftButtonUp" event don''t occur, why?
Notice: The Body is a ModelUIElement3D and some window properties set to Background="{x:Null}", AllowsTransparency="True" and WindowStyle="None".
public partial class myWindow: Window
{
public myWindow()
{
this.InitializeComponent();
Body3D.MouseLeftButtonDown+=new MouseButtonEventHandler(Body3D_MouseLeftButtonDown);
Body3D.MouseLeftButtonUp+=new MouseButtonEventHandler(Body3D_MouseLeftButtonUp);
}
private void Body_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.DragMove();
}
private void Body3D_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//After 'Body_MouseLeftButtonDown', not occur this event!
}
}
任何帮助请...
在此先感谢.
Any help pls...
Thanks in advance.
推荐答案
该事件不会发生,因为DragMove是释放按钮之前的阻塞方法.它不太可能在另一个线程上工作.
如果需要非阻塞的DragMove,我个人会使用MouseLeftButtonDown MouseMove MouseLeftButtonUp事件来滚动自己.
The event doesn''t occur because DragMove is a blocking method until the button is released. Unlikely it''s going to work on another thread.
I personally would roll my own using the MouseLeftButtonDown MouseMove MouseLeftButtonUp events if I needed a non-blocking DragMove.
在设置事件处理程序时,我看不到任何意义.无论如何,在您的Window
ystem.Windows.Window中,编写重载方法要好得多.
我检查了以下内容是否正常工作:
I cannot see any sense in setting up event handlers. In yourWindow
ystem.Windows.Window anyway, so it''s much better to write overloaded methods.
I checked up that the following works correctly:
public partial class MyWindow : Window {
public MyWindow() {
InitializeComponent();
// you could add anonymous event handlers here but there is no need to do it
// for Window events, see below
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) {
base.OnMouseLeftButtonDown(e);
isMouseDown = true;
this.DragMove();
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) {
base.OnMouseLeftButtonUp(e);
isMouseDown = false;
}
bool isMouseDown; //do you use it?
} //class MyWindow
我看不出您是否使用isMouseDown
进行任何操作?您是否真的需要此状态,因为不需要拖动它?希望你能做到.
祝你好运,
I don''t see if you use isMouseDown
for anything? Do you really need this status for something else, because for dragging it''s not needed? I hope you do.
Good luck,
这篇关于为什么要"this.DragMove()"?举行其他一些“事件"吗?尚未解决!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!