Question

How do I know when is a value of any control changed by user input (interaction with mouse or keyboard)?

Any suggestions? Is there a common way for this?

EDIT:

I am seeking for attached property or extending already given controls or whatever is needed just to get notified whether user input is taking place at the time value is changed. eg ComboBox SelectedItem changed by user input (User could enter text or select an item in drop down menu)

Its pure View thing therefore I am sorry but no ViewModel solutions for this issue will be accepted.

Was it helpful?

Solution

The simplest way would simply be to register to the Binding.TargetUpdated event, which is fired when the UI-side is updated (while Binding.SourceUpdated is fired when the ViewModel-side is updated)

OTHER TIPS

Use a property with backing field in your view model. Introduce a second setter - a SetProp() method - that you use inside your ViewModel. That way you can add different behavior, depending on the origin of the call.

```

    private bool mMyProp;
    public bool MyProp
    {
        get { return mMyProp; }
        set
        {
            if (mMyProp != value)
            {
                mMyProp = value;
                // Todo: add here code specific for calls coming from the UI
                RaisePropertyChanged(() => MyProp);
            }
        }
    }

    public void SetPropFromViewModel(bool value)
    {
        if (mMyProp != value)
        {
            mMyProp = value;
            // Todo: add here code specific for calls coming from ViewModel
            RaisePropertyChanged(() => MyProp);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top