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 pr开发者_如何学Coperties 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).
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.
If I remember correctly, Sacha Barber did something in that direction, I think you could have a look here.
精彩评论