IsDirtyChanged event?

IsDirtyChanged event?

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


Miroslav Galajda posted on Tuesday, May 22, 2012

Hi,

I was looking for event IsDirtyChanged which would indicate when IsDirty has changed.

What I found is OnIsDirtyChanged method in BindableBase class, but in the comment there is stated "This method is for backward compatibility with CSLA .NET 1.x.". And as I can see this method is never called.

I would like to implement UI indication when an business object becomes "dirty" and when it becomes "clean" by showing an asterisk in the title bar of the window.

BusinessBase class provides PropertyChanged and ChildChanged events. This is what I can use. So to encapsulate this for common use I need to create own event IsDirtyChanged which would be triggered when in PropertyChanged and ChildChanged is IsDirty is detected as changed with respect to previous remembered value.

But as you can see this is something like an old OnIsDirtyChanged() method, which is unsupported on the latest version of Csla. Is there something wrong whith this approach. Why is this method/event unsupported? Is it safe to implement this behavior?

Thank You

Yours sincerely

Miroslav Galajda

JonnyBee replied on Tuesday, May 22, 2012

Which type of UI do you use?

The typical recommendation for WPF / SL is to use the ViewModel base class that will give you meta properties as bindable properties.

Having meta state properties raise OnPropertyChanged is not recommended for Windows Forms. Adding OnPropertyChanged for all the metaproperties in Windows Forms could seriously degrade performance / user experience.

We have an issue in bugtracker concerning BusinessBase to raise OnPropertyChanged for IsXYZ properties when not in Windows Forms but work is not in progress yet.

So the proposed solution for all other platforms than .NET would be to raise PropertyChanged events on IsValid and others when user interface is not Windows Forms. You could create this yourself by overriding

    protected override void PropertyHasChanged(IPropertyInfo property)
    {
        base.PropertyHasChanged(property);
        OnPropertyChanged("IsDirty");
    }
 
    protected override void OnChildChanged(ChildChangedEventArgs e)
    {
        base.OnChildChanged(e);
        OnPropertyChanged("IsDirty");
    }

Miroslav Galajda replied on Tuesday, May 22, 2012

Unfortunately I'm developing for Windows Forms.

So what do you propose for Windows Forms?

 

Thank You

JonnyBee replied on Tuesday, May 22, 2012

I'd prefer to hook into the PropertyChanged and ChildChanged events on the "root" object in the Form and update the title based on <root>.IsDirty.

Remember to unhook before Save and rehook to the new object after Save.

Miroslav Galajda replied on Tuesday, May 22, 2012

OK, thank you.

Copyright (c) Marimer LLC