2012-07-19 3 views
0

한 번의 클릭으로 Pushpin을 배치하는 데 사용해야하는 마우스 이벤트를 찾으려고합니다. MouseUp 이벤트를 사용해 보았지만 클릭하고 드래그해도 이벤트가 실행됩니다. MouseUp을 클릭만으로 시작하고 클릭 및 드래그하지 않는 방법이 있습니까? 아니면 내가 쳐다보아야하는 다른 마우스 이벤트가 있습니까?Pushpin을 단일 클릭으로 배치

설명 : AJAX 또는 Silverlight가 아닌 Bing Maps WPF 컨트롤로 작업하고 있습니다.

+0

마우스를 움직일 때마다 실행되는 타이머가 있습니다. 그런 다음 타이머가 끝나면 MouseUp 이벤트를 수락하십시오. –

답변

0

저는 MouseLeftButtonDownMouseLeftButtonUp 이벤트를 처리하여 해킹을 관리했습니다. 얼마나 많은 시간이 경과 아래를 클릭하고 클릭을 해제 사이

private void map_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{ 
    clickTimer.Start(); 
} 

private void map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
{ 
    clickTimer.Stop(); 

    if (clickTimer.ElapsedMilliseconds < arbitraryConstant) // I find that 100 works well 
    { 
     Point mousePosition = e.GetPosition(this); 
     Location pinLocation = map.ViewportPointToLocation(mousePosition); 

     targetPin.Location = pinLocation; 

     map.Children.Add(targetPin); 
    } 

    clickTimer.Reset(); 
} 

Stopwatch 객체 기록. 이 경과 시간은 평가되어 "클릭"인지 여부를 결정합니다.

경고 : (를 클릭 드래그를하지 않는 경우 첫번째) 점진적으로 만 첫 번째 클릭 클릭을 기록 할 것 clickTimer.Reset() 또는 Stopwatch 개체를 호출하는 것을 잊지는 if 블록을 트리거합니다.

경고 : e.Handled=true으로 설정하지 마십시오. 그러면 클릭 드래그 이벤트가 방지되고지도가 제대로 이동하지 않습니다.

관련 문제