Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All I am using wpf form. I want to trigger an event if the user make any change on the form. I have already bounded the fields to linqtosql datacontext.
Let me know how do this thing.
Regards
Posted

1 solution

If you look at the Control events, you will find no event invoked when "any change" happens: https://msdn.microsoft.com/en-us/library/system.windows.controls.control_events%28v=vs.110%29.aspx[^].

Perhaps the only universal event is the method FrameworkElement.OnPropertyChanged, but the problem is: it will capture too many events, including those not related to change in data, such as changes in focused state: https://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.onpropertychanged%28v=vs.110%29.aspx[^].

This is pretty natural: such even would not be very informative, because the use of such event, not specific to what has changed, would be too limiting: you could only detect that the state of the set of controls is "dirty". Such events are specific to more concrete types of control. For example, for text boxes you can capture the text change, in list box — change of selection, in check box — the change in IsChecked state, and so on:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.textchanged(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectionchanged(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.checked(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.unchecked(v=vs.110).aspx[^].

Also, what you have to do depends on your purpose. If you use data binding, you may not need to take care of the events at the level of each control, because you can handle events at the level of data change. Please see:
https://msdn.microsoft.com/en-us/library/vstudio/ms752347%28v=vs.100%29.aspx[^],
https://msdn.microsoft.com/en-us/library/aa480224.aspx[^],
https://msdn.microsoft.com/en-us/library/aa480226.aspx[^],
WPF Data Binding - Part 1[^],
http://www.wpf-tutorial.com/data-binding/introduction[^],
http://www.wpftutorial.net/DataBindingOverview.html[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900