TextBox TextChanged event on programmatic versus user change of text contents

后端 未结 8 1741
日久生厌
日久生厌 2020-12-15 18:16

I would like to differentiate between changing the text programmatically (for example in a button click handler event) and user input (typing, cutting and pasting text). <

8条回答
  •  被撕碎了的回忆
    2020-12-15 18:37

    If you just want to use the built-in WPF TextBox, then I don't believe it's possible.

    There is a similar discussion on the Silverlight forums here: http://forums.silverlight.net/p/119128/268453.aspx It's not exactly the same question, but I think the idea similar to that in the original post might do the trick for you. Have a SetText method on a subclassed TextBox, that set a flag before changing the text and then set it back after. You could then check for the flag inside the TextChanged event. This would of course require all of your programmatic text changes to use that method, but if you have enough control over the project to mandate that I think it would work.

提交回复
热议问题