I am writing a WPF application using Self-Tracking Entities. I'm having trouble Disabling/Enabling my Save button as my Model's values are changed. Normally with the regular Entity Framework Model I am able to simply subscribe to the Model.PropertyChanged event in my ViewModel, then RaisePropertyChanged for my Save Button, which checks validation and Disabled or Enables my save button.
For some reason, with Self-Tracking Entities I noticed that the Model.PropertyChanged event is marked as protected, so I am unable to subscribe to it directly in my ViewModel. Is there any way to subscribe to this event without modifying the T4 Template??
protected virtual void OnPropertyChanged(String propertyName)
{
if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
{
ChangeTracker.State = ObjectState.Modified;
}
if (_propertyChanged != null)
{
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
protected virtual void OnNavigationPropertyChanged(String propertyName)
{
if (_propertyChanged != null)
{
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged{ add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
private event PropertyChangedEventHandler _propertyChanged;
private ObjectChangeTracker _changeTracker;
I've always just modified the template to make it not protected. It's a template for a reason :)
I suppose an alternative would be to create a public method on your class which raises the PropertyChanged notification internally.