0

PointerPressed および PointerMoved イベントを処理するコンテナー コントロールがあります。

コンテナには一連のボタンが含まれています。

イベントを処理する時点で、どのボタンが実際にイベントを受け取ったかをどのように判断できますか?

    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
    }
4

1 に答える 1

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);
            }
        }
    }
于 2012-11-02T02:00:32.133 に答える