MVVM : Cinch

Cinch is a free open source MVVM framework that I put together and will/has been released to the community. It has answers lots of the WPF/MVVM framework issues I have had when doing MVVM.

Here is a list of what Cinch contains:

  • Allows view to communicate LifeCycle events to a ViewModel without any hard reference links being maintained, and no IView interface requirements there is no link at all between the View and the ViewModel
  • Has several attached behaviours for common tasks such as
    • Numeric text entry
    • Run an ICommand in a ViewModel based on a RoutedEvent from a XAML FrameworkElement
    • Have a group of such ICommand/RoutedEvent Events for a single XAML FrameworkElement
  • Allows the ViewModel to determine is a Models data should be editable, the UI simple updates via bindings, based on the ViewModel driven editability state. This is available at individual Model field level, so it’s very flexible
  • Delegate validation rules which allows validation rules to be as granular as necessary
  • Native IDataErrorInfo support using the Delegate rules approach
  • IEditableObject usage to store/restore object state on edit / cancel edit
  • Weak event creation, to allow the creation of WeakEvents
  • Weak event subscription, which also allows auto unsubscriptions
  • Mediator messaging with WeakReference support out of the box
  • DI/IOC using Unity DI Container, to allow alternative Test/actual app service implementations
  • Service implementations which include (where Cinch has defaults for WPF/UnitTest for most of these, with the exception of the Popup window service which will be covered in a subsequent article and shall still be available within the attached demo code at any rate)
    • Event logger service
    • MessageBox service (which can be 100% emulated within unit tests, as if the user actually clicked a MessageBox button), thus enabling the ViewModel code to be traversed down the correct path
    • Open file service (which can be 100% emulated within unit tests, as if the user actually chose a file to open in the model OpenFileDialog), thus enabling the ViewModel code to be traversed down the correct path
    • Save file service (which can be 100% emulated within unit tests, as if the user actually chose a file to save in the model SaveFileDialog), thus enabling the ViewModel code to be traversed down the correct path
    • Popup window service, to control the showing/hiding and setup of Popup Window in WPF (which is a nightmare)
  • Threading helpers
    • Dispatcher extension methods to allow quick marshalling of a Action<T> to the correct UI Dispatcher
    • Application.DoEvents
    • Application.DoEvents (for a certain Dispatcher Priority)
    • BackgroundTaskManager with callback to alert waiting Unit tests of completion, to allow test to complete or timeout
    • ObservableCollection, which notifies CollectionChanged on correct Dispatcher thread
    • ObservableCollection, which allows a range of items to be added
  • MenuItem ICommand ViewModel implementation made easy
  • Closeable ViewModels (when working in Tabbed UI enviorment, which is what one should really be doing with MVVM)

Here are the links to Cinch that point to all the articles that describe how to get started with Cinch.

Cinch V2 Articles

Discussed the use of MEF and the MefedMVVM library within CinchV2

Discussed the WPF/SL and common services within CinchV2

Discussed the new features of Cinch V2 that were not in Cinch V1

A Deep Dive Into What Has Changed/What Has Stayed The Same

Disecting The WPF Demo App

Disecting The SL4 Demo App

Community Contributions / Further Articles

Convert a Silverlight Navigation Application to use MVVM using Cinch V2

Cinch Working With PRISM

Showcasing Cinch MVVM framework / PRISM 4 interoperability

3 thoughts on “MVVM : Cinch

  1. Roberto Dalmonte says:

    Hello Sacha, I’ve been using your framework since version 1, but only on the wpf side.
    Now I’m in a Silverlight project and I can’t make the CanExecuteCommand change accordinly to the IsValid property.

    I tested it in your Silverlight demo and those are the only lines of code I changed:

    SaveUserNameCommand = new SimpleCommand(CanExecuteSaveUserNameCommand, ExecuteSaveUserNameCommand);

    and this is the implementation of the CanExecuteSaveUserNameCommand:
    private Boolean CanExecuteSaveUserNameCommand(Object args)
    return IsValid;
    The button never works.
    I guess I had too many beers, since I can’t imagine this is not working..
    Can you help me out?

    Another thing I noticed is that if I change your Silverlight project (CinchSL source) from Silverlight 4 to 5 it fails to compile on this line:
    DynamicMethod dm = new DynamicMethod(
    “FastSmartWeakEvent”, typeof(bool), forwarderParameters, method.DeclaringType);
    since in version 5 there is not anymore this constructor.
    Are you planning to update your Cinch framework to Silverlight 5?

    Roberto Dalmonte

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s