-1

I have an idea of implementing holding event handler for all text-type controls ( label, textbox, passwordbox, hyperlink etc. ) in order to show message popup for allowing suggest a better translation of this text.

Is it possible to implement such type of event handler for all controls that get added/removed from/to visual tree.

Without doing such for each element:

<TextBox Holding="HoldingEventHandler"/>

I have tried this in my MainPage.xaml.cs:

AddHandler(Control.HoldingEvent, new RoutedEventHandler(HoldingOccured), true);

But it fails with exception:

Value does not fall within the expected range.

Developer
  • 4,158
  • 5
  • 34
  • 66
  • After reading the following page I wonder if the error is really caused by your line above or if there's something else wrong with your code: https://stackoverflow.com/questions/10284992/value-does-not-fall-within-the-expected-range – dnickless Jul 17 '17 at 19:09
  • @dnickless all works if this line is commented our – Developer Jul 17 '17 at 19:11
  • I reckon, the HoldingEvent is something custom. Can we see its definition? - Pls ignore, hadn't seen the UWP tag. I thought we were talking WPF here. I'm sorry. – dnickless Jul 17 '17 at 19:22
  • Does your Event Handler get called? What does the code for it look like? Have you got a stacktrace? Have you tried isolating your issue to the smallest possible example (create a new UWP project add only one textbox and the AddHandler statement - this should work in theory...)? – dnickless Jul 17 '17 at 19:52
  • 1
    Try using `RightTapped` instead of `Holding`. You might want to support mouse at some point. – Justin XL Jul 17 '17 at 21:14

1 Answers1

0

If you implement Holding in xaml and ask for new handler the system will generate the follow callback.

private void WindowsPage_Holding(object sender, HoldingRoutedEventArgs e)
{

}

So, thiis is a correct call parameters.

AddHandler(Control.HoldingEvent, new HoldingEventHandler(HoldingOccured), true);
Yuri S
  • 5,355
  • 1
  • 15
  • 23