WPF Mouse.Capture导致窗口冻结

时间:2011-03-22 09:12:17

标签: c# wpf

我有一个WPF图表,我正在图表上创建一个拖动滚动滑动窗口。我基本上遵循MouseDown-MouseMove-MouseUp序列来跟踪滑动窗口的移动。我想管理MouseDown之后MouseMove / MouseUp发生在图表区域之外的情况。为此,我在MouseDown上执行Mouse.Capture(Chart)并在MouseUp上释放捕获。但是每当MouseDown出现时,我的窗口都会挂起。我究竟做错了什么?

3 个答案:

答案 0 :(得分:3)

尝试使用:

Mouse.Capture (Chart, CaptureMode.SubTree)

答案 1 :(得分:0)

也许您处理鼠标事件不是来自Window或UserControl或其他UIElement,而是处理不是从UIElement继承的特定元素? 你需要使用

<UserControl x:Class="...
          MouseDown="HandleMouseDown" 
          .../>

而不是

<ListBox x:Name="...
            MouseDown="HandleMouseDown"
           .../>

实际上,窗口是否完全挂起,或者只是对鼠标点击没有反应(机器人在键盘上做了什么)?

答案 2 :(得分:0)

我有同样的问题。对我来说问题是由于某种原因鼠标捕获立即调用MouseMove事件,我得到了崩溃,因为我的鼠标移动事件期望在MouseDown中实例化Rectangle。当然它仍然是空的。

所以堆栈看起来像这样:

MouseDown 
  MouseCapture 
    MouseMove
then returns to where it left off in MouseDown