Using Rx over events on a WPF UserControl, why does the control receive a mousedown and mousemove when the window is maximized?

喜你入骨 提交于 2019-12-06 13:09:48

Sounds like it could be a bug in that I am not sure why a mouse move first when you maximise the window.

I would use selectMany + takeuntil instead of combine latest. ie:

var mouseDown = element.ObserveMouseLeftButtonDown().Select(ep => ep.EventArgs.GetPosition(element));
var mouseUp = element.ObserveMouseLeftButtonUp();
var mouseMove = element.ObserveMouseMove();
var from md in mouseDown  
    from mm in mouseMove.TakeUntil(mouseUp)
    where MinimumDragSeen(md, mm.EventArgs.GetPosition(element)))   
    select mm;

This will now only kick off a move when the mouse is down, and kill it as soon as the mouse is up. I dont think you have the feature of MouseUp in your code.

I would also consider trying to avoid storing the element and using it as state as I think this is available via the event Args. I would also consider using Zip on the MouseMove so you can get just the delta of the last mouse move change (if appropriate).

I would be really keen to hear about what you are doing. I am in the middle of writting a book on Rx and at work building I just finished buidling some WPF controls that use Drag Drop.

Hope that helps

Lee

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!