저는 MouseLeftButtonDown
및 MouseLeftButtonUp
이벤트를 처리하여 해킹을 관리했습니다. 얼마나 많은 시간이 경과 아래를 클릭하고 클릭을 해제 사이
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
으로 설정하지 마십시오. 그러면 클릭 드래그 이벤트가 방지되고지도가 제대로 이동하지 않습니다.
마우스를 움직일 때마다 실행되는 타이머가 있습니다. 그런 다음 타이머가 끝나면 MouseUp 이벤트를 수락하십시오. –