My MVVM Framework : AKA Cinch

I have just put up the 1st part in my MVVM series of articles which talks about a MVVM framework I am calling Cinch. I hope this will answer some of people short coming when working with MVVM and WPF. I have decided to dedicate an entire page here on my blog which will have all the links you should need to gain quick access to the entire series.

http://www.codeproject.com/KB/WPF/Cinch.aspx

http://www.codeproject.com/KB/WPF/CinchII.aspx

http://www.codeproject.com/KB/WPF/CinchIII.aspx

http://www.codeproject.com/KB/WPF/CinchIV.aspx

About these ads

13 thoughts on “My MVVM Framework : AKA Cinch

  1. I Sacha, I’m starting with your cinch and I can’t wait to dive in as deep as I can grasp of it.
    Meanwhile I want to share with you a cool implementaton of WPF Binding, INotifyPropertyChanged and Linq as found on this blog:
    http://blogs.microsoft.co.il/blogs/dorony/archive/2007/08/31/WPF-Binding_2C00_-INotifyPropertyChanged-and-Linq.aspx

    just paste the following 2 methods on your ValidatingObject.cs file
    public static string GetPropertySymbol(Expression> expr)
    {

    return ((MemberExpression)expr.Body).Member.Name;

    }

    protected virtual void OnPropertyChanged(Expression> propertyExpr)
    {

    string propertyName = GetPropertySymbol(propertyExpr);

    if (PropertyChanged != null)

    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

    }

    and in your BO classes you can avoid literals and write something like:

    public Cinch.DataWrapper OrderId
    {
    get { return orderId; }
    set
    {
    orderId = value;
    OnPropertyChanged(() => OrderId);
    }
    }

    Hope you like it.

    Too bad the project book has been canceled. I’m following your articles since a long time and I was happy about it. On a second thought I’m happy you canceled the book so you have to right energy and focus to develop cinch.
    Best Regards
    Roberto Dalmonte

  2. Jon Rodriguez says:

    Hi Sacha!
    I’ve been working around on one of your articles in the codeproject.com entitled wcf/wpf chat application. To tell you the truth, i’m using your article for my thesis. I posted a question in the forum (codeproject/wcf wpf chat app) just 12 hours ago because I’m having problems running the program. Now I write you here because I really want to communicate with you. If you could just email me to give me some directions regarding my question in the forum or just reply in the forum.

    I’m sorry to bother you but I really need your help.
    Thank you in advance.

    Jon

  3. sacha says:

    Roberto check out the updated Cinch code over at codeproject, that now has Expression Tree INPC implementation

  4. Nicola Carnevali says:

    Hi Sasha,
    I had a look at your framework and I think it’s very good and quite easy to use. I have some doubts about validation rules: adding rules to the model is good, expecially using the SimpleRule class, but I must add a new rule objects to every istance models. For example in the demo app there is a CustomerModel class that has 7 rules so we have 7 rule objects in memory per CustomerModel object. If we have a collection of 10K customers we have 70K validation rules while we actually need only 7 of them. Could there be perfomance and memory issues?
    Since these rules are stateless couldn’t we add them to a per class static collection (like Karl’s Ocean framework)?
    Of course we still need to add different rules for each model instance but we could have two way to add rules. What do you think?

    I also think (but it’s just a matter of taste) that the ValidatingObject class could be split in 2: the base class should only implements INPC (like Josh Smith’s ObservableObject) while the ValidatingObject should contain the remaining logic. This because sometimes you only need property change notification therefore a more lightweight object would be easier to use.

    Thanks
    Nicola

  5. sacha says:

    Nicola

    Great comments.

    The Rules one, I think I may look into that. If you have some code / ideas Id love to see them. But I’ll have a look when I have some time. That said the standard way to do validation is to have the rules hard coded into the Model using what Microsoft suggest with the IDataErrorInfo implementation.

    http://blogs.msdn.com/wpfsdk/archive/2007/10/02/data-validation-in-3-5.aspx

    Which of course means we have the same problem. So from that point of view I do not feel too bad about my approach. But Ill look into it, or if you have something in mind send it my way, Id love to see it.

    As far as ValidatingObject / INPC goes, yeah I think if people want an ObservableObject they can add there own its not so much work. As you say its down to personal taste.

  6. Nicola

    Looks at this again, this can very easily be solved IU think. Just move where the rules are created so instead of the Ctor just move them into the Static Ctor for the object. That way the rules are only declared once per type, not per instance.

    And as you say they store no state, so that should be fine.

  7. Hey Sasha,

    For an assignment for school we had to use MVVM, so after evaluating some of the most popular frameworks, I’ve decided to use your piece of art. Thanks to your extensive articles and well-commented source code, I had little trouble getting everything up and running. I do want to point out one thing that I believe is wrong in one of your articles (http://www.codeproject.com/KB/WPF/CinchII.aspx#validationRules). Here you give an example how to add rules to simple types, but a simple type like Int32 hasn’t got a .AddRule method ofcourse, so instead of quantity.AddRule(..), I think it should be this.AddRule(…)

    If I’m mistaken, excuse me.

    Thanks for bringing out such full-featured framework,

    Dieter

    PS: Sorry for my english

    • sacha says:

      No you are correct as Int32 is not a DataWrapper and doesnt inherit from ValidatingObject, you do have to do what you said, which is use this.AddRule()

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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