EventToCommand + DataStateBehavior eases MVVM pain

NOTE: This was cross posted from here .

MVVM is a pattern.  There are all sorts of MVVM frameworks popping up that help make implementing the pattern easier.  If you select the MVVM tag off of www.codeplex.com, you will find a number of them:

https://www.codeplex.com/site/search?TagName=MVVM&ProjectSearchText=%22MVVM%22

One I have recently grown fond of is https://mvvmlight.codeplex.com/.  The reason I like this one is because they have built an Expression Blend Behavior called EventToCommand.  Details for the behavior:

https://blog.galasoft.ch/archive/2009/11/05/mvvm-light-toolkit-v3-alpha-2-eventtocommand-behavior.aspx

As the post says, ‘EventToCommand is used to bind an event to an ICommand directly in XAML.”

This is WAY COOL!!!  EventToCommand helps overcome commanding challenges in Silverlight.

I love Blend Behaviors.  If you haven’t looked into them, YOU MUST!  Every WPF and Silverlight developer should be using them (where applicable).  “A Behavior is in essence a reusable piece of interactivity that can be applied directly to user interface elements...”

Here are some resources:

Good Overview - https://tinyurl.com/BehaviorsOverview

More reading - https://tinyurl.com/BehaviorsTriggersActions

Expression Blend 3 SDK - https://tinyurl.com/blend3sdk 

Lots of folks creating and uploading them to Expression Gallery - https://tinyurl.com/BehaviorsGallery

Behaviors from the Blend Team - https://expressionblend.codeplex.com/

Behaviors are part of the Blend SDK.  There is a lot of confusion about the Blend SDK because people think you have to buy Blend to use it.  You don’t!  You can download it from https://tinyurl.com/blend3sdk and use it straight from Visual Studio.  Blend definitely makes wiring up Behaviors easier so you should it for that if you are already using Blend!

The samples you can download from https://expressionblend.codeplex.com/ include DataStateBehavior and DataStateSwitchBehavior.  Peter Blois has a good post on these behaviors:

https://blois.us/blog/2009/04/datatrigger-bindings-on-non.html

DataStateBehavior/DataStateSwitchBehavior provide a nice clean way to change values in your ViewModel that result in initiating animations in your View.

I’ve been wanting to whip up a simple sample that shows both EventToCommand and DataStateBehavior/DataStateSwitchBehavior.Unfortunately, I don’t have the time right now to do so.  Instead of sitting on this, I decided to blog about it first, then share a sample/video when I get around to it.

-Marc