Property change notification and Dirty state

Property change notification and Dirty state

Old forum URL: forums.lhotka.net/forums/t/5927.aspx


i_am_deebo posted on Wednesday, December 03, 2008

I have a business object, call it BizObject, that contains a List.  I want to add a property on BizObject, call it IsListOkay, that returns true if the List it contains is in a "valid" state.  Since IsListOkay is databound in a ListView and shows a different icon depending on it's state I created IsListOkay as a "dependency" property.  This works great, whenever the state of the List changes the icon on my list view updates automatically thanks to databinding.  The problem is whenever the List changes it changes BizObject.IsSelfDirty to true.  Is there anyway to avoid this?

In other words, is it possible to use change notification on a property without it affecting the objects dirty state?

ajj3085 replied on Wednesday, December 03, 2008

Instead of calling PropertyHasChanged, you can call OnPropertyChanged directly.  This won't run any validation rules though, so you'll have to do that also if you don't call PropertyHasChanged.

SonOfPirate replied on Wednesday, December 03, 2008

Correct me if I'm wrong, but doesn't IsSelfDirty only look at validating BizObject itself?  IsDirty should reflect the state of any child objects or collections.

 

RockfordLhotka replied on Wednesday, December 03, 2008

That's true, but the state of a list is the combined states of its child objects. So any changed object in a list means the list has been changed.

SonOfPirate replied on Wednesday, December 03, 2008

Right, but if I change a LineItem contained in my OrderItems collection, then Order.IsDirty would return true but Order.IsSelfDirty should remain false, yes?

From the original description, it sounds to me like BizObject is an object that has a collection property.  BizObject.IsSelfDirty should not be true if only the collection has changed - unless the list's changed event is bubbled into a PropertyChanged event on the root BO, which would cause _isDirty to be true if PropertyHasChanged is called (instead of directly calling OnPropertyChanged).

 

i_am_deebo replied on Wednesday, December 03, 2008

Yes, that is what's happening.  I didn't mention that BizObject keeps IsListOkay updated by listening to the list changed events.  Calling OnPropertyChanged directly fixed my problem.  Thanks.

Copyright (c) Marimer LLC