Hey guys,
You might have seen it already, but I just posted a new alpha of the MVVM Light Toolkit. Featured in this release is a new behavior named EventToCommand. This behavior can be added to any FrameworkElement (including panels, shapes, etc…) and can bind any event of this element to an ICommand (typically on the ViewModel). Since it is a behavior, you have all the benefit of rich Blend support, but adding it in XAML is not that hard either.
It is inspired of the Blend team’s InvokeDataCommand (with the Blend team’s blessings ;)), but with a few additions:
· You can data bind the CommandParameter (also in Silverlight) or set a hard coded value if you prefer.
· You can choose (opt-in) to have the attached element be automatically disabled when CanExecute returns false. This is dynamic, i.e. it reacts to ICommand.CanExecuteChanged. This is an opt-in, because since you can have multiple EventToCommand on one single element, you probably don’t want them to fight to set the state of the control.
o In Silverlight, this works only on Controls, because other elements don’t have IsEnabled.
o In WPF, this works for any FrameworkElement, so you can disable/enable a panel, for example, and use Style.Triggers to modify the visual appearance.
For this component, I create an “Extras” DLL in order to keep the “essentials” lightweight. The Extras is optional, and will contain added value components such as this one. It does also require System.Windows.Interactivity.
More info here:
There is a sample application too. Note that the code is alpha, so changes to the API are possible, but it is well tested, so most bugs should be out. I’d love feedback if you have some.
Cheers,
Laurent
--
Laurent Bugnion [Microsoft MVP, MCP]
Blog: http://blog.galasoft.ch
Support children in Calcutta: http://www.calcutta-espoir.ch
|
|
as |