tags:

views:

25

answers:

3

I need to do call a function according to any data change in WPF (C#) page, that is if any of the data of the current page is changed such as Textbox, Radiobutton, Checkbox, Combobox, Datagrid etc then I need to call a function how can I do it without using different event ?

A: 

You can use dependency properties in your code and bind to it from your control. That will allow changes in your control or your code to automatically updated.

Vitalij
A: 

Implement INotifyPropertyChanged in the class, Raise the property changed notification in all properties setters.

HTH

Avatar
A: 

If you put this in your code behind it will call Handler for every event

If u put this after InitializeComponent

InitializeComponent();

foreach (RoutedEvent event in EventManager.GetRoutedEvents())
{
    AddHandler(event, new RoutedEventHandler(Handler), true);
}

You can have it execute the Handler method. This will attach it to every event.

void Handler(object sender, RoutedEventArgs e) { Title = e.ToString(); }

Alternatively you can just set the events that you want for example text changed to the same method, or you can use a linq query or some logic in the foreach loop to only attach to certain events.

Hope this helps

Wegged