tags:

views:

385

answers:

1

It appears that the ValueChanged and SourceUpdated events will fire simply by setting the DataContext. Does anyone know of a way to tell whether the value changed is actually from some user interaction?

A simple example is to have a "Save" button on a WPF form that is disabled until the user actually changes the data. Since both ValueChanged and SourceUpdated events fire when the DataContext is set, I can't simply enable the "Save" button without determining what actually caused the event to fire in the first place.

Thanks in advance.

A: 

Without knowing more details about your implementation (your UI architecture, etc.) I can provide only general advice.

  1. If you have a Presentation Model, bind the enabled-ness of the Save button to a property on your PM, which is governed by changes made to other properties on your PM.

  2. If your coding directly against your code-behind, defer binding the Save button until AFTER you set the DataContext.

One thing that you want to keep in mind is that setting the DataContext is like changing the DataBinding of all the controls where you are not setting the Source explicitly. Relying on DataContext to let you simply specify the Path, but you have to account for that cascading behavior.

micahtan