Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any MVVM frameworks that play nice with RoutedCommand?

RoutedCommand and RoutedUICommand have a lot going for them. There's baked-in support for text and for keyboard gestures. You can bind a collection of RoutedUICommands to a Menu's ItemsSource and it will automatically create and bind menu items for you. Some commands (Cut, Copy, Paste) are automatically supported by out-of-the-box controls.

However, whenever I use MVVM, I've found routed commands to be a poor fit, because of the repetitive boilerplate XAML and codebehind I have to write for each one. When I'm doing MVVM, I've usually wound up using RelayCommand instead of routed commands. This is an adequate workaround some of the time, but it has downsides -- for example, key gestures become much more complicated.

But after watching Rob Eisenberg's "Build your own MVVM Framework" session, I'm no longer satisfied with relay commands and their shortcomings. The only problem with routed commands was the repetitive boilerplate code, and once you factor that repetitive code out into a framework, and apply conventions, there no longer seems to be any reason not to use routed commands in MVVM.

Technically, it looks like this would not be hard. The framework should just need to bind to the view's CommandManager.CanExecute and Executed events, and apply conventions to look for methods and properties on the ViewModel -- for example, when the Cut command is executed, look for an ExecuteCut method (and CanExecuteCut property) on the ViewModel. I could build my own MVVM framework that made this easy.

But my question is, are there already MVVM frameworks that work with RoutedCommand? The only MVVM framework I'm familiar with in any depth is Caliburn.Micro, and it doesn't currently support routed commands this way (which surprises me, since it does support its own flavor of action bubbling).

like image 528
Joe White Avatar asked Nov 21 '10 01:11

Joe White


People also ask

What framework for MVVM should I use?

The Windows Presentation Framework (WPF) takes full advantage of the Model-View-ViewModel (MVVM) pattern.

What is routed command in WPF?

WPF-routed commands give you a specific mechanism for hooking up UI controls such as toolbar buttons and menu items to handlers without introducing a lot of tight coupling and repetitive code into your application.


2 Answers

with lot of research marathon in SO and other sites, didnt find any proper framework to PLAY with RoutedCommand.

but one of the WPF Disciple Josh Smith has implemented a nice solution of using Routed Command with MVVM.

you can Check Using RoutedCommands with a ViewModel in WPF, which is stated as clean and lightweight to use RoutedCommands in MVVM architecture.

like image 109
Binil Avatar answered Oct 14 '22 21:10

Binil


If I remember correctly, Sacha Barber did something in that direction, I think you could have a look here.

like image 43
Felice Pollano Avatar answered Oct 14 '22 22:10

Felice Pollano