2012-01-25 6 views
1

필자는 WPF 앱에서 TouchDown에 대한 좌표를 얻고이 터치 아래에 어떤 UI 요소가 있는지 찾는 방법을 읽었을 것입니다. 누구든지 도와 줄 수 있습니까?터치 좌표에서 UI 요소 가져 오기

+0

왜이 터치의 '아래'에있는 UI 요소를 알고 싶습니까? 그것을 조작에서 제외해야합니까? 언제 필요합니까? 조작 델타에서? – simo

+0

저는 페이지 스 와이프 조작에서 제 단추를 제외하는 방법을 알아 내려고 노력했습니다. * 한숨 * 여기를 참조하십시오 : http://goo.gl/pCdVSr – Jordan

답변

0

시각적 트리에 대해 hit test을 수행해야합니다. 여기

이와 예입니다 마우스 클릭 (하지만 터치가 더 많거나 적은 같은이 점에서 일) : HitTest

// Respond to the left mouse button down event by initiating the hit test. 
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{ 
    // Retrieve the coordinate of the mouse position. 
    Point pt = e.GetPosition((UIElement)sender); 

    // Perform the hit test against a given portion of the visual object tree. 
    HitTestResult result = VisualTreeHelper.HitTest(myCanvas, pt); 

    if (result != null) 
    { 
     // Perform action on hit visual object. 
    } 
} 

다른 과부하가 당신에게 여러 히트 영상을 제공 할 수 있습니다.

+0

이 예에서 myCanvas 란 무엇입니까? – Matt

+0

Manipulation의 콘텐츠를 필터링하면됩니까? http://goo.gl/pCdVSr – Jordan

0

은 UI 요소는 다음과 같이 UIElement에 클래스를 확장하자 : 방금 e.Cancel();

를 호출 할 필요가 특정 요소에 대한 조작을 취소해야하는 경우

class MyUIElement : UIElement 
    { 
     protected override void OnManipulationStarting(System.Windows.Input.ManipulationStartingEventArgs e) 
     { 
      base.OnManipulationStarting(e); 
      UIElement involvedUIElement = e.Source as UIElement; 

      // to cancel the touch manipulaiton: 
      e.Cancel(); 
     } 
    } 

involvedUIElement가 터치 이벤트를 발생시킨 UI 요소를 보유해야

도움이되기를 바랍니다.