-3

I have user setting objects with observablecollections in it. My problem is that saving the settings are only saved one time. I guess that the setting object gets no change event by the collections. I tried to fix this by a collection Changed event but in this case my handler is always null.

My question is: Can I force my Save method to write ALL data or as an alternative is there a way to instantiate the Propertychanged event handler on my own( not by framework)

Thanks for any help

1 Answers1

0

Settings is a partial class, so you can create the other partial part and put your saving logic there. Something like

public partial class MySettings
{
    protected override void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
            Save();
        base.OnPropertyChanged(sender, e);
    }
}

ObservableCollection fires a PropertyChanged event when the Count changes, so this should work too, for adding and deleting from the ObservableCollection.

  • Thanks for your time. the problem is that onpropertychanged is not called. I "solved" this problem by reassigning the properties to the settings like Setrtings.Default.Setting1 = Setrtings.Default.Setting1; – user2582903 Mar 21 '18 at 09:42
  • Sorry to hear that. I'm using the same method with my WPF application and it works fine, although I don't use Observable collections in the settings. Does it work for simple properties? Perhaps there's a mismatch between namespaces in the settings.designer.cs and your partial. –  Mar 21 '18 at 22:07