2012-11-02 12 views
0

PointerPressed 및 PointerMoved 이벤트를 처리하는 컨테이너 컨트롤이 있습니다.어떤 자식 컨트롤이 Pointer * 이벤트를 받았는지 검색합니다.

컨테이너에는 일련의 버튼이 있습니다.

이벤트를 처리하는 시점에서 실제로 어떤 버튼이 실제로 수신되었는지 확인할 수 있습니까?

mainPage.AddHandler(PointerPressedEvent, new PointerEventHandler(pointerPressedHandler), true);   
    private void pointerPressedHandler(object sender, PointerRoutedEventArgs e) 
    { 
     var p = e.GetCurrentPoint(null); // maybe can be done using position info? 
     var s = e.OriginalSource as Border; // OriginalSource is a Border, not the Button, and I don't seem to be able to get to the Button from the Border 

     // todo - determine which button was clicked 
    } 

답변

0

이 작동 :

private void pointerPressedHandler(object sender, PointerRoutedEventArgs e) 
    { 
     var p = e.GetCurrentPoint(null); 
     var elements = VisualTreeHelper.FindElementsInHostCoordinates(p.Position, mainPage, false); 

     Button foundButton; 
     foreach (var item in elements) 
     { 
      foundButton = item as Button; 
      if (foundButton != null) 
      { 
       System.Diagnostics.Debug.WriteLine("found button: " + foundButton.Name); 
      } 
     } 
    }