开发者

Loss of Silverlight mouse up events after mouse capture?

I created a very simple test control that has a Rectangle on a canvas (within other containers, but inconsequential). The Rectangle has event handlers for mouse down, mouse move, and mouse up. If I capture the mouse in the Rectangle's MouseLeftButtonDown event, I do not receive a corresponding MouseLeftButtonUp event.

Some code:

private void rect1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    if (_captured = CaptureMouse())
    {
        _offset 开发者_JAVA技巧= new Point(Canvas.GetLeft(rect1), Canvas.GetTop(rect1));
        _origin = e.GetPosition(RootCanvas);
        e.Handled = true;
    }
}


private void rect1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    if (_captured)
    {
        ReleaseMouseCapture();
        _captured = false;
        e.Handled = true;
    }
}

I attached event handlers for the container elements as well, just to make sure one of them wasn't getting the mouse-up event somehow, but none of them were. Is there an expectation of this in Silverlight that I haven't yet learned?


I think you are little confused about what is actually capturing the mouse events.

Consider when you do this:-

 if (_captured = CaptureMouse())

what object is the CaptureMouse actually being called against?

Answer: The user control for which your code is the code-behind. Had you wanted the rectangle to capture the mouse you would do:-

 if (_captured = rect1.CaptureMouse())


CaptureMouse(); from mouseDown Event and then try.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜