Not sure if this already came up but could we add virtual OnModelXyz methods for all the attached events in OnModelChanged.
If I want to do any processing based on those then I have to basically replicate OnModelChanged and then pay attention to any future changes.
Thanks
jack
Hi Jack ,
See this issue: http://www.lhotka.net/cslabugs/edit_bug.aspx?id=730
Checked in 2 days ago and available in CSLA 4 repository.
If you have time - you can download the latest version from repository and try out.
Those were the changes I thought I had seen mentioned before. However what I was looking for was some of the other private methods. I overrode OnModelChanged so that I could attach/detach from the same events to expose the private methods. It would be nice to not have to attach/detach from the same events over and over.
I posed my override of OnModelChanged. Mostly I'm looking to trap changes to certain properites in my ViewModel so I can do something to the UI.
Jack
protected override void OnModelChanged(T oldValue, T newValue)
{
base.OnModelChanged(oldValue, newValue);
if (ReferenceEquals(oldValue, newValue)) return;
// unhook events from old value
if (oldValue != null)
{
var npc = oldValue as INotifyPropertyChanged;
if (npc != null)
npc.PropertyChanged -= Model_PropertyChanged;
var ncc = oldValue as INotifyChildChanged;
if (ncc != null)
ncc.ChildChanged -= Model_ChildChanged;
var nb = oldValue as INotifyBusy;
if (nb != null)
nb.BusyChanged -= Model_BusyChanged;
}
// hook events on new value
if (newValue != null)
{
var npc = newValue as INotifyPropertyChanged;
if (npc != null)
npc.PropertyChanged += Model_PropertyChanged;
var ncc = newValue as INotifyChildChanged;
if (ncc != null)
ncc.ChildChanged += Model_ChildChanged;
var nb = newValue as INotifyBusy;
if (nb != null)
nb.BusyChanged += Model_BusyChanged;
}
OnViewModelChanged(EventArgs.Empty);
}
protected virtual void Model_BusyChanged(object sender, BusyChangedEventArgs e){}
protected virtual void Model_PropertyChanged(object sender, PropertyChangedEventArgs e) {}
protected virtual void Model_ChildChanged(object sender, ChildChangedEventArgs e){}
Copyright (c) Marimer LLC