This project has moved. For the latest updates, please go here.

Ideas for .NET 4.5

Coordinator
Mar 9, 2012 at 8:58 PM

I published the package WAF for .NET 4.5 (Experimental) which shows some new ideas I have for the WPF Application Framework (WAF). These ideas won’t come in the 2.5 release because the 2.5 release targets the .NET Framework 4.0 version. But some of them might be seen in one of the next major releases.

Highlights

1. Simplify the usage of the INotifyPropertyChanged interface

New methods in the Model class simplify raising the PropertyChanged event.

Classic approach:

public object ContentView
{
    get { return contentView; }
    set
    {
        if (contentView != value)
        {
            contentView = value;
            RaisePropertyChanged("ContentView");
        }
    }
}

New approach:

public object ContentView
{
    get { return contentView; }
    set { SetReference(ref contentView, value); }
}

The new approach uses the CallerMemberName attribute which is a new feature of .NET 4.5. The compiler creates the property name directly in the assembly. This way the new approach is type safe and doesn’t come with performance penalties like a lot alternative approaches do.

In this package I have implemented two different Set methods for value types and reference types: 

  • SetValue: Sets a new value type and raises the PropertyChanged event. 
  • SetReference: Sets a new reference type (object) and raises the PropertyChanged event.

 
2. Better WeakEvent support by the .NET Framework

The WAF base classes Controller and DataModel provide an improved weak event support because working directly with the WeakEventManagers was cumbersome and error-prone. The new .NET Framework comes with an enhanced API which makes the WAF weak event support obsolete.

Weak events with WAF:

AddWeakEventListener(fileService, FileServicePropertyChanged);
AddWeakEventListener(fileService.Documents, DocumentsCollectionChanged);

Weak events with .NET 4.5:

PropertyChangedEventManager.AddHandler(fileService, FileServicePropertyChanged, "");
CollectionChangedEventManager.AddHandler(fileService.Documents, 
    DocumentsCollectionChanged);

 
3. MEF supports now dependency injection of NonShared parts

Until .NET 4.5 the creation of NonShared parts was only possible via the Service Locator approach. It had to be done by calling GetExportedValue on the Container. Now it is possible to import a factory which is able to create the NonShared parts.

Service Locator approach with .NET 4.0:

[ImportingConstructor]
public FileController(CompositionContainer container, IMessageService messageService, ...)
{

...

// Show the save changes view to the user
ISaveChangesView saveChangesView = container.GetExportedValue<ISaveChangesView>();
SaveChangesViewModel saveChangesViewModel = new SaveChangesViewModel(saveChangesView, 
modifiedDocuments); bool? dialogResult = saveChangesViewModel.ShowDialog(shellService.ShellView);

New approach with .NET 4.5:

[ImportingConstructor]
public FileController(..., FileService fileService, ExportFactory<ISaveChangesView> saveChangesView)
{

...

// Show the save changes view to the user
SaveChangesViewModel saveChangesViewModel = new SaveChangesViewModel(
saveChangesView.CreateExport().Value, modifiedDocuments); bool? dialogResult = saveChangesViewModel.ShowDialog(shellService.ShellView);

 
4. Usage of WPF Ribbons

The Writer sample application comes with Ribbons. Now the application looks a lot more modern and trendy.

Sep 24, 2012 at 1:45 PM

I've noticed several updates to WAF since the experimental version was released.  Do you plan an update to the experimental version in the near future?  If not, will you roll the .NET 4.5 features into the official WAF soon?  I am hoping to launch on a military enterprise application soon and we will be targetting .NET 4.5.

Thank you!

Coordinator
Sep 30, 2012 at 9:14 AM

I have planned to release a stable version of WAF 2.5 soon. It will target .NET 4.0 but will run under .NET 4.5 as well.