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
3
votes
1 answer

Find destination of a RoutedEvent

When I execute a routed command, let's say: ApplicationCommands.Undo.Execute(null, this); WPF does some magic to find the proper CommandBinding on which it executes the ExecutedRoutedEventHandler. Is there a way to get a reference to the…
Stefan
  • 4,187
  • 1
  • 32
  • 38
3
votes
1 answer

Can I use Caliburn to bind to RoutedCommands?

What's the best way to use WPF's built-in RoutedCommands with Caliburn? For example, in my shell I have an Edit menu with a Copy item in it attached to the standard command found in ApplicationCommands:
GraemeF
  • 11,327
  • 5
  • 52
  • 76
3
votes
1 answer

Can I bind a RoutedCommand to a Command in WPF?

I have a ViewModel of the form: class VM : DependencyObject { // This class exposes a command to data binding to delete things from the model public static DependencyProperty DeleteProperty = DependencyProperty.Register(/*...*/); public…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
3
votes
1 answer

How to launch RoutedCommand on application level in multiple windows pattern?

I have a multiple windows in an application, for instance, window1, window2 and window3. one RoutedCommand (with KeyGesture F11) was binded in window1. How to launch that routed command by pressing F11, while window2 had input focus ? In WinForm…
user244980
  • 47
  • 4
3
votes
1 answer

Executed gets not called after PreviewExecuted

Here's my code: var commandBinding = new CommandBinding(ApplicationCommand.New); commandBinding.PreviewExecuted += OnPreviewExecuted; commandBinding.Executed += OnExecuted; CommandBindings.Add(commandBinding); void OnPreviewExecuted(object sender,…
Stephan
  • 53
  • 6
3
votes
1 answer

AvalonDock + UserControl + DataGrid + ContextMenu command routing issue

I'm getting weird behavior with command propagation from MenuItems of ContextMenu. I have the following kind of layout: ContextMenu is set for each DataGridRow of DataGrid inside UserControl, which in its turn is inside DockableContent of…
repka
  • 2,909
  • 23
  • 26
3
votes
3 answers

Is it possible to have CommandManager requery only specific WPF command instead of all?

I'm trying to implement a highly responsive UI for my MVVM application, so I've chosen to have all command handlers automatically execute in a BackgroundWorker so they don't block the UI. But at the same time, I don't want the user to be able to…
aoven
  • 2,248
  • 2
  • 25
  • 36
3
votes
1 answer

RoutedCommands in Silverlight

Is it possible to use RoutedCommands such as ApplicationCommand.Copy, ApplicationCommand.Paste, etc in Silverlight 4 beta version ?
Ganesan
  • 109
  • 11
3
votes
1 answer

How to override Copy command on WPF textbox?

I would like to override the behavior of RoutedUICommand "Copy" of a WPF TextBox. Is it possible without creating a new TextBoxExtended class that inherits from TextBox? I have reached that point, but now I am bit lost. Private Sub…
Drake
  • 8,225
  • 15
  • 71
  • 104
3
votes
2 answers

RoutedCommands that use tunneling instead of bubbling

I have a custom control (MyControl) that exposes a custom command. I want the parent Window to be able to invoke this command, and all MyControls should react to it. I have added the command to MyControl's CommandBindings collection, which also…
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
2
votes
3 answers

Executing WPF routed commands manually

When executing a custom RoutedUICommand manually from code-behind, like this: MyCommands.MyCommand.Execute(parameter, target) do I need to call the CanExecute method first or is this already done inside the Execute method?
Oskar
  • 7,945
  • 5
  • 36
  • 44
2
votes
2 answers

RoutedCommand with parameter

I'm playing around with RoutedCommand, and I'm having an issue with finding how can I pass a parameter so that my Executed method will have it in e.Parameter ? My RoutedCommand: public static readonly RoutedCommand Foo = new…
pguzewicz
  • 304
  • 2
  • 13
2
votes
1 answer

Best place to put implementation code of custom WPF command (RoutedUICommand) handlers

In WPF, custom commands have event handlers such as command_Executed and command_CanExecute, the best practice is that the implementation logic should not be directly implemented in the code-behind class, and it should only contain function calls to…
SpeedBirdNine
  • 4,610
  • 11
  • 49
  • 67
2
votes
1 answer

WPF: ApplicationCommands seem to ignore CommandTarget

I have a TextBox and a ListView in my window, and I'd like to move the ListView's selection up and down while the TextBox has focus: However, I don't seem to get my CommandTarget declarations across, they're ignored. MSDN says this is default…
Jan
  • 683
  • 10
  • 18
2
votes
1 answer

How is the RoutedCommand.Name property used?

The RoutedCommand class has a Name property that can be set in the contructor. MSDN has this to say about RoutedCommand.Name: This property can be used when referencing a RoutedCommand in XAML. However, I can't seem to find information on how to…
Matthew
  • 28,056
  • 26
  • 104
  • 170