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
4
votes
2 answers

What should be owner type of a routed command?

I am using wpf Custom Commands. While writing a custom Command, one need to define the owner type. It's Description says that it is the type that is registering the command. I was seeing some sample of custom commands and there the Owner type was…
viky
  • 17,275
  • 13
  • 71
  • 90
4
votes
1 answer

WPF Two Commands handlers, One Command

Im deriving from a third party control. It is implementing ApplicationCommands.SelectAll. However the behaviour i want is slightly different. there is no virtual method i can override, and when i register a class handler, like so …
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
4
votes
1 answer

How to requery 'CanExecute' of a single RoutedCommand?

I need to refresh the CanExecute state of one or more (though by far not all) RoutedCommand objects. I know that you can update all commands by using CommandManager.InvalidateRequerySuggested(); Since this updates far more commands than necessary,…
floele
  • 3,668
  • 4
  • 35
  • 51
4
votes
1 answer

WPF - how do I extend (or work in parallel with) the built-in command mechanism?

Please excuse me if this is a dumb question - I have read a dozen articles on the WPF command infrastructure and I am more confused than ever. I understand that I can use the built-in commands to implement (for example) a toolbar that will apply…
Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
4
votes
2 answers

How can a CanExecute of a commandBinding fire once the element has been removed from the visual tree?

I have a related question here where i have a user control with a command binding. The user control has being removed from the visual tree, yet the canExecute is still firing. My understanding of the Commanding model was that it bubbles and tunnels…
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
4
votes
1 answer

Do I have to use CommandTarget? I thought any focused element would receive the Command

I'm trying to understand how to use RoutedCommands. I was under the impression that if I don't specify a CommandTarget on the Button, any focused element will receive the command. But for some reason it doesn't work. Here is the xaml that doesn't…
luddet
  • 1,235
  • 1
  • 11
  • 11
3
votes
1 answer

How to rewrite WPF routed commands dispatching mechanism

Can I extend WPF commands routing in a way so it would first check whether command can be invoked in the focused field and if not in some other (never changing)? Is there any hooks for that? Maybe you don't know whether that would work but saw…
Sergej Andrejev
  • 9,091
  • 11
  • 71
  • 108
3
votes
2 answers

How and where do ICommands fit into the overall WPF MVVM pattern?

I'm trying to learn how to use WPF commands, and how they fit into the MVVM pattern. I understand that some controls, like a button or menu, have a Command property which when set to an instance of an ICommand class connects the button to that…
Eric Anastas
  • 21,675
  • 38
  • 142
  • 236
3
votes
1 answer

Standalone Command Objects in WPF

Is it possible / practical to implement WPF commands as standalone objects? If so, how is this typically done? Most of the examples I see about commanding typically involve using RoutedCommand, RoutedUICommand, or some other implementation of…
mclark1129
  • 7,532
  • 5
  • 48
  • 84
3
votes
2 answers

WPF - Why do ContextMenu items work for ListBox but not ItemsControl?

Items in a list have context menus. The context menu items are bound to routed commands. The context menu items work correctly if the list control is a ListBox, but as soon as I downgrade it to an ItemsControl it no longer works. Specifically the…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
3
votes
0 answers

Can I Raise CanExecute on MediaCommands without using InvalidateRequerySuggested()?

I have some custom CommandBindings that determine the CanExecute status of various MediaCommands (Play, Pause, etc). I'd like to trigger the CanExecute handler to be called at certain points. However, the only way I can figure out how to do this is…
JacobJ
  • 3,677
  • 3
  • 28
  • 32
3
votes
2 answers

WPF - Custom Control + ICommand (How do I Implement this)?

Basically, I have a custom control FooControl. public class FooControl : ItemsControl { //Code } I need to add some event handling, but rather than using a RoutedEvent I'd much more prefer to use Commanding instead. I'm not really sure how to…
michael
  • 14,844
  • 28
  • 89
  • 177
3
votes
2 answers

How do I pass a specific viewmodel object in a button's CommandParam?

I have a simple WPF program using the Master-Detail UI pattern, where the Detail shows the currently selected item of a collection in the Master pane. I'm using MVVM, and each XAML page is backed by a ViewModel object which is set as it's…
Mike Garrett
3
votes
1 answer

Is there any way to alias commands in WPF?

Is there any way to effectively "alias" commands in WPF ? My situation is this : I've created an application that uses ApplicationCommands.Delete in the context of a graphical editor that has a number of customized canvases. Some of the controls…
Alex Marshall
  • 10,162
  • 15
  • 72
  • 117
3
votes
1 answer

What is the purpose of the text argument of RoutedUICommand

I am implementing some RoutedUICommand and could not figure out the purpose of the text argument. The reason for my question is: I am wondering if it is necessary to translate this text or not. Is it just a descriptive text for the…
ˈvɔlə
  • 9,204
  • 10
  • 63
  • 89
1 2
3
11 12