CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

IsDirtyChanged event?

Answered (Verified) This post has 1 verified answer | 4 Replies | 1 Follower

Top 200 Contributor
44 Posts
Miroslav Galajda posted on Tue, May 22 2012 6:11 AM

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

Answered (Verified) Verified Answer

Top 10 Contributor
1,813 Posts
Verified by Miroslav Galajda

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");
    }

Jonny Bekkum, Norway CslaContrib Coordinator

All Replies

Top 10 Contributor
1,813 Posts
Verified by Miroslav Galajda

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");
    }

Jonny Bekkum, Norway CslaContrib Coordinator

Top 200 Contributor
44 Posts

Unfortunately I'm developing for Windows Forms.

So what do you propose for Windows Forms?

 

Thank You

Top 10 Contributor
1,813 Posts

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.

Jonny Bekkum, Norway CslaContrib Coordinator

Top 200 Contributor
44 Posts

OK, thank you.

Page 1 of 1 (5 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems