Computed fields AUTO INPC for Mvvm Light

This very small library is bringing INPC to computed fields with just a single attribute.
It works with Mvvm Light 5.1.1+ but can be adapted for other versions.
Current lib has been tested for VS 2015 and UWP/UAP (Windows 10).

Auto INPC works against ObservableObject and children classes like ViewModelBase or any class based on ObservableObject (Model classes are often based on the latter).

USAGE

  1. Add the DotBlog.MvvmTools library to your project references
  2. Add in the constructor a call to AutoInpc.Initialize(this)
  3. Add the ComputedFieldAttribute to all computed fields, specifying the name(s) of "trigger" fields

SAMPLE

Giving a Mvvm Light ViewModel declaring the two following properties :

public string FirstName { .... }
public string LastName { .... } 


Now you can create the following property using the special ComputedFieldAttribute and it will automically send an INPC (mostly for the UI) when any trigger field will be modified:

[ComputedField(new []{"FirstName","LastName"})]
public string FullName => FirstName + " " + LastName; 


Do not forget to add in the class constructor a call to AutoInpc.Initialize(this). Keep a token on the returned instance so you can use the suspended mode.

public MainViewModel()
        {
            token = AutoInpc.Initialize(this);
            .... }

BONUS

Auto INPC library is offering a "suspended mode". While in this mode no INPC are sent for computed fields, they are all recorded in a waiting list and grouped to avoid double calls.
This is very usefull when you have to modify multiple fields at the same time and just want one final INPC for the computed fields, saving CPU and avoiding incomplete data problem in computed fields.

What's in the bag

  1. The source code of the DLL project
  2. A test project showing how to use the lib

Editor

This lib has been writen by Olivier Dahan, Microsoft MVP "Windows Platform Dev", MVP since 7 years.
The project is edited by http://www.e-naxos.com a French company.
More doc will be soon available on http://www.e-naxos.com/blog "Dot.Blog" (in French but Google translator is making a not so bad job ir you're not speaking French). Just search for "autoinpc".

What next

It will be cool to create a Nuget package for example.
The lib can also be adapted for other MVVM frameworks.

If you want to help and join the project, be welcome!

Visual Demo

Last edited Aug 23, 2015 at 5:21 PM by odahan, version 11