0

Is there a way to check if a given UIElement takes text input? I see there's a UIElement.TextInput event handler so I could add/remove handlers, but of course I can't check if it is null (if at least one handler has been added to it).

I'm guessing it's not possible but maybe there's a workaround I don't know about.

daniloquio
  • 3,822
  • 2
  • 36
  • 56
  • You're trying to verify that it's a TextBox? Can you just look for a child named `PART_ContentHost`? – Brannon Jan 09 '20 at 21:25
  • Why not looking at their types? there should be a finite number of UIElement types in your app which take text input, and they might act differently upon input. – Bizhan Jan 09 '20 at 21:25
  • @Brannon no, I wanted to check if the control handled TextInput (NumericUpDown, ComboBox, TextBox, etc). – daniloquio Jan 09 '20 at 21:31
  • @Bizhan you're right, that's the approach I already implemented. The problem is 1) performance (with 30 input controls on the list and a check for every keydown the impact is significative. 2) Mainteneability (keep the list up to date as new text taking controls are used by developers on the coming years). – daniloquio Jan 09 '20 at 21:33
  • a solution to both is to have a custom library for wpf elements. or you can add an attached property to the UIElement and set it "once" instead of on every key down. – Bizhan Jan 09 '20 at 21:48
  • @Bizhan That's what I end up doing, it works very well. Thanks – daniloquio Jan 10 '20 at 01:37

0 Answers0