Cinch (My MVVM framework) Part 6 is out

I just published part VI of my MVVM framework series over at .

Here is the link


This time I talk about

What the demo app looks like, and pointing you at all the relevant parts that cover the demo app, as discussed in all the previous Cinch articles.





  1. Nice app Sacha, and LOL, “there’s no going back” with that colour scheme (Sacha knows what this means). I’ve been catching up on this since I returned from holiday… I like the vague familiarity of the app and the Unit Testing…


  2. Martyn, me old mukka hows tricks. Things here are kinda ok actually, we have some new blood, and I think that may be a good thing.

    OMNI web is on the table, which sounds fun. Ill catch up with you soon off this thread in provaite email.


  3. Sacha,

    I have been following this series since you announced its existence. I am getting up to speed finally on WPF and MVVM as a result of it. I am using Cinch and WPF Toolkit for some of the controls. I have hit a road block on one item related to foreign keys and pulling the right display data. If you have the time i would love to pick your brain a bit.




  4. Morgan,

    Whilst I think it’s great you like and are using Cinch, foreign keys and pulling the right display data doesn’t sound like a Cinch issue. In fact that is really down to your own Business Requirements, which is nothing to do with what Cinch is about.

    If you have a Cinch specific query, I Could answer that.

    I hope you see what I mean.


  5. Sacha:,
    I have a couple questions:

    1. Should Cinch have any issues being used with Silverlight 3?

    2. I have read that you dont like Prism much as it doesnt do what you want and thats alright. I wanted to know if you found any specific issues with EventAggregator & DelegateCommand. Personally I dont think they are very different than Mediator and RelayCommand. I see your point with lots of projects an dnot being able to see everything in blend design, but how else would we handle modularity and seperate teams working on seperate business parts/modules of project that are loosely interconnected. What are your comments on this?

    3. What problems do you see with mixing Cinch’s MVVM/ Editing/ErrorValidation/MessageBoxes etc with Prism modularity?

    I am looking at a fairly decent sized Healthcare LOB app in Silverlight… and maybe a WPF counterpart later.


  6. Because I am a bit busy (or lazy?) I have been waiting for you to release an app built on Cinch before I take a closer look 🙂

    You have been churning out these article pretty fast – are they basically parts of the book you were working on?

    Colin E.


  7. Colin

    The Cinch stuff wa supposed to be for the book, though I had not written any text until I did the codeproject articles, that is just the speed I work at.

    And Part 1 had a demo app from the very start, you did not have to wait.

    But there you go. I am now working on a Cinch code generator


  8. Imran

    Thanks for your interest

    1. I have not tried it with SL, and probably will not try it. I developed it as a WPF library, and that is what I think it should be used for. By all means try it, but just know that I have not.

    2. I do like certain PRISM aspects, however I do not like the EventAggregator, I tried that once and had 2 control both hhoking up to a Loaded aggregated event, and both could fir the event too, and it just blew my mind how it worked, it seemed very very weird to me. Probably just me.

    3. Should be ok I think, as CInch is really just about ViewModels so I do not really see an issue there, as long as the DataContext is a Cinch VM and what you are trying to bind with uses examples like in the articles, it should be ok.

    Good luck with the Healthcare app, if you want a nice SL framework try Oynx or Laurent Buginions MVVM light (especially for SL I think).

    Mine was and always will be a WPF library, as I prefer WPF.


  9. Thank you Sacha for the prompt response and refrences, I will look into Onyx and laurent’s MVVM.

    I see your point on EventAggregator, however I think its more of a feature that any module can fire a _specific event_ which can be subscribed anywhere, its fits very well with the Modularity concept.

    I will update you on my experience with mixing Cinch with Prism. I still have to figure out two issues though:

    1. Unlike the WPF controls, the SL controls don’t support ICommand stuff inherently so DelegateCommand or RelayCommand doesnt not work out-of-the-box. To be able to handle view events in viewmodel, you either have to sacrifice the cause of no-code-in-code-behind OR one ends up writing lots of attached behavior code for button click, list item select and so on. I wonder if there is a framework that does that attached behaviors in SL for us out of the box.

    2. I think WPF (and SL for sure) support only one ICommand per UI control, which is kind of disappointing. I will be abe to use Delegate/RelayCommand for ListItemSelected only and will have to fall back to codebehind if I want another event for ListItemDoubleClicked etc.

    Does Cinch or any other framework have an answer for these issues?


  10. Imran

    1. Not as far as I am aware
    2. Yeah only suports 1 Command per ICommandSource. SO its attached behaviour city for you.

    Good luck thanks for the comments


  11. Hello Sacha,

    Cinch is ACE! nice one.
    How/where do you set the DataContext to enable databinding between the view & view models?
    I don’t see it being… WPF just has too much magic going on…:) still thanks for sharing this great work.

    What will be nice is to see a sequence diagram to see how things flow from clicking the AddCustomer button to data being saved in the database. That should demystify some of the magic eh? what do you think?

    Nice one and Big UP Sacha!!


  12. Corku

    The DataContext is set in the code behind in the MainWindow to MainWindowViewModel. From there is all DataTemplates applied to the TabControl is MainWindow

    If I find time to do a diagram I will, right now I am working on a Cinch ViewModel code generator to make it even easier to use Cinch.


  13. Hello sacha!
    I use some part of your code, and i think it is great, but i have noticed that in the SingleEventCommand you creat a delegate with a strong reference to a EventHooker object couple ( Command, Event), why don’t you turn EventHooker into a singleton.

    and why don’t you add a DependencyProperty for the CommandParms.

    Sorry for my bad english.


  14. Benmouffok

    Thanks for the comments Ill look into it. You can use the Collection that have parameters, I may even dicth Event hooker in favour of collection of CommandEvents as explained in articles text.

    Ill look into Strong reference.



  15. I can just second what Gorku said, a sequence diagramm for your Cinch sample app would be very helpfull for us bloody noobs 😉


  16. hello sacha,

    for example i use it like this

    private static void EventChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
                string eventName = e.NewValue as string;
                string oldEventName = e.OldValue as string;
                if ( d == null )
                    throw new NullReferenceException("This behavior can only be installed on DependencyObject!");
                if (!string.IsNullOrEmpty(oldEventName))
                    EventInfo oldInfo = d.GetType().GetEvent(oldEventName, BindingFlags.Instance | BindingFlags.Public);
                    if (oldInfo != null)
                        oldInfo.RemoveEventHandler(d, EventHandlerHelper.getDelegate(oldInfo));
                if ( string.IsNullOrEmpty(eventName))
                EventInfo info = d.GetType().GetEvent(eventName, BindingFlags.Instance | BindingFlags.Public);            
                if ( info == null )
                    throw new NullReferenceException(string.Format("Event name {0} has not been found on this object !", eventName));
                info.AddEventHandler(d, EventHandlerHelper.getDelegate(info));            
    with the class EventHandlerHelper
    sealed class EventHandlerHelper
            private static readonly EventHandlerHelper _instance = new EventHandlerHelper();
            public static Delegate getDelegate(EventInfo info)
                return Delegate.CreateDelegate(info.EventHandlerType,
                                                _instance.GetType().GetMethod("OnEventRaised", BindingFlags.NonPublic | BindingFlags.Instance));
            private void OnEventRaised(object sender, EventArgs e)
                var source = ((DependencyObject)sender);
                var command = source.GetValue(SingleEventCommand.CommandProperty) as ICommand;
                var parm = source.GetValue(SingleEventCommand.CommandArgsProperty);
                if (command != null)

    i also use e.OldValue for unregister the event if any.

    perhaps that can be useful for you.

    Thanks for your answer.


  17. Hey Sacha! i cant find a good place to post this, so ill try here first. I need your expertise!!
    Im having a problem with my ViewModels never being GC’ed until the app is shutdown. This is a major issue! Can you pros lend some ideas as to exactly what could be the cause of them never being released? Im using a tabbed style app, where you can open as many Entity tabitems(viewmodels) as you want, and then close them when youre done. The examples Ive seen from disciples they always limit the number of open VMs at once…am I missing something, doing something wrong? Im using Joshs/Marlons Mediator to send out messages, with a static Mediator singleton in my base viewmodel…could that be a culprit?



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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s