locked
How to detect the tap on repeat button in scrollviewer RRS feed

  • Question

  • I have a UWP application where I am tracking the PointerPressed event on my ListView:

    MyListView.AddHandler(PointerPressedEvent, new PointerEventHandler(OnPointerPressed), true);
    
    private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
    {
        var originalSource = e.OriginalSource;
        if (originalSource is TextBlock) //it is true if the repeat button was clicked but it is true for many other instances as well. so not a reliable way
        {
            // Do stuff
        }
    }

    I can see that the text of the textblock would come out to be the exact shape on the repeat button (up and down arrow). But I cannot compare it in code since it seems to be a code and not a text.



    Tuesday, June 14, 2016 12:04 PM

Answers

  • Hi Ashishks1987,

    The up/down RepeatButton define the text by the Glyph="" and Glyph="". So we can check the text if they equal to the Unicode of the up/down glyph.

    For example:

    private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
    {
        var originalSource = e.OriginalSource;
        if (originalSource is TextBlock)
        {
            if ((originalSource as TextBlock).Text == "\uE0E4")
            {
            }
            else if ((originalSource as TextBlock).Text == "\uE0E5")
            {
            }
        }
    }
    

    Best Regards,

    Jayden Gu

    • Proposed as answer by Barry Wang Thursday, June 23, 2016 12:05 PM
    • Marked as answer by Barry Wang Friday, June 24, 2016 1:28 AM
    Monday, June 20, 2016 12:41 PM

All replies

  • What exactly are you are looking to compare?

    You can use following code to get binding detail for the row which is clicked. Replace ClassName with your binding object.

    var fe = sender as FrameworkElement;
    var item = fe.DataContext as ClassName;


    Gaurav Khanna | Microsoft .NET MVP | Microsoft Community Contributor


    Tuesday, June 14, 2016 4:32 PM
  • I want to know when the up/down repeatbuttons are clicked in order to scroll through the listview. I cannot rely on checking the DataContext actually. Is there any other way to do it?
    Wednesday, June 15, 2016 5:52 AM
  • Hi Ashishks1987,

    The up/down RepeatButton define the text by the Glyph="" and Glyph="". So we can check the text if they equal to the Unicode of the up/down glyph.

    For example:

    private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
    {
        var originalSource = e.OriginalSource;
        if (originalSource is TextBlock)
        {
            if ((originalSource as TextBlock).Text == "\uE0E4")
            {
            }
            else if ((originalSource as TextBlock).Text == "\uE0E5")
            {
            }
        }
    }
    

    Best Regards,

    Jayden Gu

    • Proposed as answer by Barry Wang Thursday, June 23, 2016 12:05 PM
    • Marked as answer by Barry Wang Friday, June 24, 2016 1:28 AM
    Monday, June 20, 2016 12:41 PM