locked
How can I implement long press on button in WinRT by C#/XAML?

    Question

  • Hi, everyone.

    How can I implement long press on button in WinRT by C#/XAML?

    I tried to catch PointerPressed and PointerReleased events on buttons

    in order to calculate the time between pressed and released to make long press.

    But I cannot catch those event on buttons.

    Any other good way to make long press on button?

    Thursday, May 24, 2012 11:28 AM

Answers

  • Hi FunkeeMastah,

    As mentioned in my previous post, the button handles the PointerPressed and PointerReleased events for its own use.

    You could try overriding the button's OnPointerPressed and OnPointerReleased methods to get access before the button handles them.

    If that doesn't work, since you don't want standard button behavior you could write your own control.

    --Rob

    • Marked as answer by FunkeeMastah Wednesday, June 27, 2012 11:52 AM
    Tuesday, June 26, 2012 5:39 PM
    Owner

All replies

  • The button handles the PointerPressed and PointerReleased events for its own use.

    You could try overriding its OnPointerPressed and OnPointerReleased methods to get access before the button handles them.

    Note that a long press is non-standard and likely to confuse your users. Timed based interactions such as press-and-hold are explicitly called out as against the touch interaction guidelines (you're using a mouse here, but the concept is the same).

    --Rob

    • Marked as answer by Jesse Jiang Friday, June 01, 2012 8:21 AM
    • Unmarked as answer by FunkeeMastah Tuesday, June 26, 2012 12:33 PM
    Thursday, May 24, 2012 3:48 PM
    Owner
  • Thank you for quick reply.

    But...

    in XAML

    <Button x:Name="test_button"/>

    In code behind

    test_button.PointerPressed += test_button_PointerPressed;

    void test_button_PointerPressed(object sender, PointerRoutedEventArgs e)
    { // can not enter here..
    }

    (but I can catch test_button.Click event)

    I tried to calculate time between PointerPressed EventHandler and PointerRelease EventHandler in order to implement Press-and-hold action on a button control.

    But I can't catch PointerPressed and PointerRelease.

    any other ways to suggest?

    thank you.

    • Marked as answer by FunkeeMastah Tuesday, June 26, 2012 12:32 PM
    • Unmarked as answer by FunkeeMastah Tuesday, June 26, 2012 12:32 PM
    Friday, June 22, 2012 2:19 AM
  • Hi FunkeeMastah,

    As mentioned in my previous post, the button handles the PointerPressed and PointerReleased events for its own use.

    You could try overriding the button's OnPointerPressed and OnPointerReleased methods to get access before the button handles them.

    If that doesn't work, since you don't want standard button behavior you could write your own control.

    --Rob

    • Marked as answer by FunkeeMastah Wednesday, June 27, 2012 11:52 AM
    Tuesday, June 26, 2012 5:39 PM
    Owner