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


























Roberto DALMONTE said
am July 23 2009 @ 7:12 am
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
sacha said
am July 23 2009 @ 7:40 am
I have seen loads of this. I would prefer to use Bill Kempf Reflect code.
http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!694.entry
sacha said
am July 25 2009 @ 10:47 am
Roberto check out the updated Cinch code over at codeproject, that now has Expression Tree INPC implementation
Nicola Carnevali said
am July 30 2009 @ 3:04 pm
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
sacha said
am July 30 2009 @ 3:26 pm
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.
Nicola Carnevali said
am July 30 2009 @ 3:53 pm
Sure, I’ll send you something as soon as I have optimized the code.
Thanks,
Nicola
XAMLCast – 2a Temporada – Episódio 7 – Silverlight Viewport, Visual Studio 2010 RC, MVVM - redeRIA | Agregador de noticias, artigos, tutoriais Flex, Flash, JavaFX, AJAX e Rich internet applications em geral! said
am February 17 2010 @ 5:43 pm
[...] http://sachabarber.net/?p=522 [...]
Dieter Bocklandt said
am February 21 2010 @ 6:10 pm
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 said
am February 22 2010 @ 7:09 am
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()