2016-04-08 7 views
0

画面にいくつかの点を描き、マウスの左ボタンを押したままドラッグできるコードがあります。マウスイベントが発射を停止し、ドラッグされているポイントが動きを止めることを除いて、これはちょっとしたことです。キャプチャされた要素のマウスイベントは、ドラッグ中に発砲を停止します。

すべてのイベントが(何らかの不明な理由により)捕捉されなくなるため、ユーザーは何も起こることなくマウスの左ボタンを放すことができます。

奇妙なことは、ポイント上でマウスの位置を変えることができ、マウスの左ボタンを押さなくても再びドラッグを開始できることです。これは非常に貧弱なユーザーエクスペリエンスになります。

何が起こっていますか?

pinPoint.MouseLeftButtonDown += Point_MouseLeftButtonDown; 
pinPoint.MouseLeftButtonUp += Point_MouseLeftButtonUp; 
pinPoint.MouseMove += Point_MouseMove; 

. 
. 
. 

void Point_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{ 
    ((UIElement)sender).CaptureMouse(); 
    if (_isDragging == false) 
    { 
     _isDragging = true; 
    } 
} 

void Point_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
{ 
    _isDragging = false; 
    ((UIElement)sender).ReleaseMouseCapture(); 
} 

void Point_MouseMove(object sender, MouseEventArgs e) 
{ 
    //where the point gets moved and some other logic 
    //possibly this logic takes too long? 
} 

答えて

0

解決策が見つかりました。私はまだそれがなぜMouseCaptureを絶えず失っているのか分かりません。

pinPoint.LostMouseCapture += Point_LostMouseCapture; 

. 
. 
. 

void Point_LostMouseCapture(object sender, MouseEventArgs e) 
{ 
    //if we lost the capture but we are still dragging then just recapture it 
    if (_isDragging) 
    { 
     ((UIElement)sender).CaptureMouse(); 
    } 
} 
関連する問題