views:

19

answers:

1

My view model MyViewModel has a property MyProperty that i need to read/save from/to the application's settings. My project has Settings.settings file and the Settings type has MyProperty property. i need to bind MyViewModel.MyProperty to Settings.MyProperty so that any changes to MyViewModel.MyProperty are reflected in the Settings.MyProperty, and possibly the other way around. how can i do that?

note that i cannot derive MyViewModel from Settings because MyViewModel already derives another type.

EDIT: i can do it manually of course: read and write from and to Settings in my property definition, but i am asking whether there is a more elegant approach.

class MyViewModel : ViewModelBase
{
    public int MyProperty { ... }
    public MyViewModel()
    {
        // here i need to bind Settings.Default.MyProperty to this.MyProperty
    }
}
A: 

rather than having the MyProperty on MyViewModel, you could treat the Settings object as another ViewModel (have it implement INotifyPropertyChanged). you can have more than one ViewModel. this would reduce duplication, obviously.

Alex Lo