Is it possible to know if any of the textbox values have changed in the application. I have around 30 textboxes and I want to run a part of code only if, any of the textboxes value has changed out of the 30. Is there a way I can know that.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You can also just do this:
In your Constructor:
And Then this Method:
try this. Add this code to the load/constructor. no need to specify the event in the XAML explicitly
You can assign an event handler to each of the TextBox's TextChanged events. All of them can be assigned to the same event handler in code. Then you'll know when the text changes. You can set a boolean flag field in your class to record that a change occurred.
Each text box will raise an event
TextChanged
when it's contents have changed. However, that requires you to subscribe to each and every event.The good news is that you can subscribe to the event with the same method multiple times. The handler has a parameter
sender
which you can use to determine which of your 30 text boxes has actually raised the event.You can also use the GotFocus and LostFocus events to keep track of actual changes. You would need to store the original value on
GotFocus
and then compare to the current value onLostFocus
. This gets round the problem of twoTextChanged
events cancelling each other out.This is perhaps on the rough and ready side, but I did it this way.
In the constructor, I created
bool bChanged = false;
In the TextChanged event handler of each control (actually same for each), I put
bChanged = true;
When appropriate, I could do some processing, and set bChanged back to false.