开发者

WPF Mouse.Capture causes window to freeze

I have a WPF chart and I'm creating a drag-to-scroll sliding window on the chart. I'm essentially following a MouseDown-MouseMove-MouseUp sequence to track the sliding window movements. I want to manage cases where a MouseMove/MouseUp after a MouseDown occurs outside the chart area. For this, I'm doing a Mouse.Capture(Chart) on MouseDown and Releasing the capture on MouseUp. But whenever the MouseDown occurs, my window hangs. What am 开发者_StackOverflowI doing wrong?


Try using this:

Mouse.Capture (Chart, CaptureMode.SubTree)


Maybe you handle mouse events not from Window or UserControl or other UIElement, but on specific element that not inherits from UIElement? You need use

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

Instead of

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

Actually, did the window hangs completely or just does not react to mouse clicks (bot do on keyboard)?


I had the same issue. The problem for me was that the mouse capture for some reason immediately calls the MouseMove event, and I was getting a crash because my mouse move event was expecting a Rectangle to be instantiated in MouseDown. Of course it was still null.

So the stack looks like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜