Questions tagged [routed-commands]

WPF: Defines a command that implements ICommand and is routed through the element tree.

The WPF implementation of ICommand is the RoutedCommand class.

The main sources of input in WPF are the mouse, the keyboard, ink, and routed commands. The more device-oriented inputs use a RoutedEvent to notify objects in an application page that an input event has occurred. A RoutedCommand is no different. The Execute and CanExecute methods of a RoutedCommand do not contain the application logic for the command, but rather they raise routed events that tunnel and bubble through the element tree until they encounter an object with a CommandBinding. The CommandBinding contains the handlers for these events and it is the handlers that perform the command.

RoutedCommand Class

Commanding Overview

170 questions
85
votes
6 answers

Boolean CommandParameter in XAML

I have this code (which works just right): True
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
52
votes
2 answers

ICommand vs RoutedCommand

Let's have a button Command property bound to a custom command. When should I implement ICommand and when derive from RoutedCommand? I see that RoutedCommand implements ICommand. In which case could I need to implement an ICommand? What about MVVM…
theSpyCry
  • 12,073
  • 28
  • 96
  • 152
30
votes
2 answers

When to use events over commands in WPF?

Hi i have recently looked into WPF and started learning about Events and Commands. I typically use Commands on Button clicks which causes a method to Run in my "view model". Is it possible to make the Button react to any other events like the…
CAA
  • 355
  • 3
  • 5
20
votes
5 answers

WPF Commands, How to declare Application level commands?

I'm interested in creating commands that are available from anywhere in my WPF application. I'd like them to work in the same way as Cut, Copy, Paste and the other Application level commands, ie:
ocodo
  • 29,401
  • 18
  • 105
  • 117
19
votes
1 answer

What is the difference between a RoutedCommand and a RoutedUICommand?

I have tried to do some reading about it, but I failed to find documentation that explains the difference between RoutedCommand and RoutedUICommand satisfactorily.
Dabblernl
  • 15,831
  • 18
  • 96
  • 148
15
votes
3 answers

How can I handle WPF routed commands in my ViewModel without code-behind?

According to my understanding of MVVM, it is a good practice to handle routed commands directly in the ViewModel. When a routed command is defined in a ViewModel as a RelayCommand (or DelegateCommand), it is easy to bind directly to the command…
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
12
votes
2 answers

How to bind ApplicationCommands to a ViewModel?

I have successfully used a few custom commands using MVVM-Light, but I want my application to respond to the standard ApplicationCommands, not just at a Window level, but at a detailed item level as well. I have a TreeView that I want to be able to…
mbmcavoy
  • 2,628
  • 5
  • 23
  • 34
12
votes
2 answers

In WPF how do I implement ICommandSource to give my custom control ability to use Command from xaml?

Could you please provide a sample, of how do you implement the ICommandSource interface. As I want my UserControl, which doesn't have the ability to Specify command in xaml, to have this ability. And to be able to handle the command when user clicks…
Vitalij
  • 4,587
  • 9
  • 42
  • 65
11
votes
2 answers

What use has RoutedCommand' class constructor ownertype argument?

The constructor of the RoutedCommand has "owner type" as a last argument. What is its significance? When it is used? MSDN documentation gives completely no clue about why it's needed and whether I could use one type for all commands Quote from…
Sergej Andrejev
  • 9,091
  • 11
  • 71
  • 108
11
votes
6 answers

WPF TextBox Intercepting RoutedUICommands

I am trying to get Undo/Redo keyboard shortcuts working in my WPF application (I have my own custom functionality implemented using the Command Pattern). It seems, however, that the TextBox control is intercepting my "Undo" RoutedUICommand. What is…
Joseph Sturtevant
  • 13,194
  • 12
  • 76
  • 90
9
votes
3 answers

Should I check an ICommand's CanExecute method before calling Execute from procedural code?

When using ICommands in XAML, WPF uses the CanExecute method to enable or disable controls associated with the command. But what if I am calling Execute from procedural code? Should I first check CanExecute to make sure that the command can…
Matthew
  • 28,056
  • 26
  • 104
  • 170
9
votes
2 answers

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…
Joe White
  • 94,807
  • 60
  • 220
  • 330
9
votes
4 answers

How do I programmatically fire a command

I have an ICommand that I want to fire (make the execute go) from code; how do I do this?
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
8
votes
1 answer

How to move my RoutedCommand handler from View-codebehind to ViewModel?

The following RoutedCommand example works. However, the handling for the button which executes the command is in the codebehind of the view. The way I understand MVVM, it should be in the ViewModel. However, When I move the method to the ViewModel…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
8
votes
2 answers

Implement custom Copy and Paste in WPF DataGrid which works when there are no rows in it

I need to implement a custom copy + cut + paste for data (not text or CSV) to be copied between grids in a WPF application. Using standard ApplicationCommands and defining CommandBinding works really well but only if the DataGrid contains at least 1…
too
  • 3,009
  • 4
  • 37
  • 51
1
2 3
11 12