We built an large application based on Composite Application Library and MVVM using Infragistics controls.
In orde
I don't agree with this, I have worked on a large scale buisness application using WPF, MVVM, WCF and Telerik controls. In the beginning, using MVVM was a bit tough but once we settled with our design and the View model framework it became very easy. Reusability was very easily achievable and development time was also reduced.
Moreover it was really very easy to change the controls altogether; in some places we had used basic WPF controls which we later replaced with telerik controls and vice versa(as in some places we didn't required heavy telerik controls like GridView). I can say that if needed we could have easily replaced all telerik controls with some other 3'rd party controls or native WPF controls easily any time.
But yes, we had to implement some workarounds while using telerik controls and write some code in codebehind to solve some issues(bugs in telerik); all that code was purely presentation logic.
A view model is good because it makes databinding easier. Databinding does not cover all that you need to do, so some code attached to the XAML is convenient.
In my experience a mix of view model and attaching to events seems to get the job done until a more pure approach can be worked out if required.
EDIT:
Attaching to events does not necessarily break the MVVM model if you use the event handler to forward the event to handler logic in your viewmodel or some other responsible object.
There are advantages to pure databinding in that you can more easily make different XAML skins which use the same viewmodel. One example is to have a debug skin which exposes some of the inner workings to help in development and a working skin which is the end product. The different XAML views can bind to the same viewmodel.
Hey, whatever works for you. It's all too easy to get religious about this stuff. My apps slide into spaghetti code unless I pay pretty strict attention to Separation of Concerns, but that doesn't mean MVVM is the only way to go. If you've got an app that works, and one that you can change without a bunch of cascading side effects, then I'd say go with it.
I would respectfully disagree (no downvote) with Anderson Imes on one point: I don't find MVVM difficult to stick with; I find it very easy. To me, it is the simplest and most natural approach to designing WPF apps. I use it within the framework of Composite WPF (Prism), which provides a very robust framework for partitioning complex apps.
I have written a CodeProject article on implementing MVVM in a real-world app. Hopefully, people just getting into MVVM will find it helpful.
I started doing WPF applications in a FFA (free-for-all) design pattern like this and I won't go back it, even for a small projects. Though it feels like you are more productive going right to the source, bare-metal UI, I came to the conclusion it's more a perception of productivity because you get instant gratification.
Consider: TextBlock.Text = "HelloWorld"
. No ViewModel to construct, no gluing the V and VM or binding setups. Hit F5 and we see "HelloWorld" in all it's glory. My problem with this is multifaceted. Here is a couple of my biggest issues:
Separation of concerns. Without it, code navigation, bug fixing, extensibility and general maintenance is severely hindered. Adding a feature to an application would be more liken to a choose-your-own-adventure book or an exercise in quantum physics than it is actually getting something done. If you have a predictable way to build your app, you have a predictable way to work on it.
Flexibility of the UI. When using the FFA pattern, I found my ability to design UI in my applications was near impossible. Too many times did I have a control I couldn't design in Blend. It would just give a red border with an exception. Some code-behind I had used something else that wasn't usable in design mode causing an issue. Moving to MVVM magically fixed all my Blend issues. If I get a red border in Blend now, I KNOW it's a problem with my presentation code. Not anything else.
So using FFA may get your V1 out the door quick, but the PHBs will be wondering why v1.5 is going to take four times longer than v1. We've all been there :)
I think if you want to do something like this, I would work with lookless controls, where you define UI "PARTS", making it very Blendable. You get reference to the UI controls via the OnApplyTemplate. These controls are totally stylable and inheritable. It is your View where you would use these controls and pull data from binding, passing it to your lookless controls. The View, IMO, should always be glue for the VM to bind to these kinds of controls.
For the Infragistics controls you are having problems with, assuming you are using Prism, you should make a custom region adaptor for it. This lets you code EXACTLY how controls will be added to the Infragistics. No binding involved. View injection will just work like you are used to once you get that built in.
I've seen some people have problems like these in MVVM, but I believe it's just taking MVVM too literally. Not everything gets evented by a messenger. My ~40 view (and growing) application has around 5 composite events. I inherit controls, I use view injection on things that aren't even panels or content controls. Sometimes I have codebehind handle presentation related code/events...And...really, I advocate MVVM and I don't give a @$&% about testing :)
Advocates of MVVM over state their case. They claim that the alternate to MVVM is necessarily spaghetti code. What Edward describes is still following a pattern, it's just not MVVM. The fact that Views bind to Models is similar to MVC. The code behind can be considered the controller.
Clearly, he feels the results are better in terms of development effort AND maintainability. Since the latter is the only valid rationale for a design pattern, the case against his approach isn't clear.
Saying "you don't understand MVVM" isn't really an argument against his approach. A pattern that is easier to understand is better than one that isn't.
I tried this and ended up going back to MVVM. You end up with the same event-driven spagetti-coded mess you always ended up with in Windows Forms. If I never have to do another myLabel.Text = this.MyLabelText
I will be happy.
Don't get me wrong - MVVM is harder to stick with and you really have to know WPF to pull it off.
You lose a lot by not using it, though, including a lot of the ability to use Expression Blend to style your controls and DataTemplates.