Questions tagged [routed-commands]
WPF: Defines a command that implements ICommand and is routed through the element tree.
routed-commands
190
questions
86
votes
6
answers
72k
views
Boolean CommandParameter in XAML
I have this code (which works just right):
<KeyBinding Key="Enter" Command="{Binding ReturnResultCommand}">
<KeyBinding.CommandParameter>
<s:Boolean>
True
...
78
votes
4
answers
54k
views
MVVM Routed and Relay Command
What is the Difference between the RoutedCommand and RelayCommand ?
When to use RoutedCommand and when to use RelayCommand in MVVM pattern ?
52
votes
2
answers
43k
views
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 ...
30
votes
2
answers
7k
views
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 ...
20
votes
5
answers
28k
views
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:
&...
19
votes
1
answer
4k
views
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.
15
votes
3
answers
7k
views
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 ...
12
votes
2
answers
6k
views
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 ...
12
votes
2
answers
12k
views
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 ...
11
votes
6
answers
5k
views
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 ...
11
votes
2
answers
2k
views
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 ...
9
votes
4
answers
10k
views
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?
9
votes
3
answers
2k
views
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 ...
9
votes
2
answers
2k
views
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 ...
8
votes
2
answers
22k
views
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 ...
8
votes
2
answers
35k
views
Setting Command Target in XAML
I am having a hard time understanding the CommandTarget property for a RoutedCommand.
Basically, I have some static commands that have implementations in a user control (not the window). I create a ...
8
votes
1
answer
4k
views
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.
...
7
votes
1
answer
3k
views
RoutedCommands Executed and PreviewExecuted events
My problem is that I would like to handle a commands in multiple places. For instance I have my custom UserControl where a Button is bound to some command. I have a command binding in that control but ...
7
votes
1
answer
427
views
Separating views, command presentation (Text, Icon) and command logic (Execute, CanExecute)
If TL;DR: see the last paragraph.
Pure WPF "suggests" putting presentation (controls, text, icons) into views and command logic (Execute, CanExecute methods) into code-behind. Besides putting logic ...
7
votes
1
answer
1k
views
How to intercept execution of a RoutedCommand within the view?
In a WPF / MVVM application, I am trying to find a code-efficient way to set the main view cursor to Cursors.Wait prior to any lengthy operation and to restore it to the default cursor after ...
6
votes
4
answers
8k
views
multi key gesture in wpf
I have a RoutedUICommand called Comment Selection. I need to add an input gesture for this command as it is in VIsual Studio, ie. (Ctrl+K, Ctrl+C).
How can I do this? Plz help me. (Keep VS ...
6
votes
3
answers
12k
views
Loopback in Route table
I and working on a project to create a WAN emulator using FreeBDS in a VMWare guest configured to route traffic between the host operating system and its normal gateway router. I plan to modify the ...
5
votes
4
answers
9k
views
WPF using custom RoutedUICommands or simple event handlers?
I was talking to someone today about picking a design pattern for how to handle logic in their WPF program and hoping that the SO community can help with further advice to make the decision easier. ...
5
votes
4
answers
3k
views
Do WPF Routed Commands solve a problem or make it worse?
From what I understand, the goal of the Command pattern is to help separate UI interaction from application logic. With properly implemented commands, a click on a "Print" menu item might result in a ...
5
votes
1
answer
4k
views
RoutedUICommand within MVVM
I am struggling with MVVM in my application. I have there a TabControl whose every Tab hosts a control that allows somehow editing a file. For instance, text files or images. Each control is bound to ...
5
votes
2
answers
1k
views
RoutedUICommand PreviewExecuted Bug?
I'm building an application using the MVVM design pattern and I want to make use of the RoutedUICommands defined in the ApplicationCommands class. Since the CommandBindings property of a View (read ...
4
votes
1
answer
3k
views
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 ...
4
votes
1
answer
3k
views
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 ...
4
votes
1
answer
4k
views
Passing ListView Items to Commands using Prism Library
I'm trying to execute methods based on listview items data. In addition to that, the button, which triggers the command, should only be enabled, if "CanExecute" method of the listview item returns ...
4
votes
1
answer
933
views
Show InputGestureText as a tooltip for a Button
A have a Button with a Command. I want to display the InputGestureText as a ToolTip for every button that contains a command.
This is what I tried:
<n:ImageButton x:Name="NewRecordingButton" Text=...
4
votes
2
answers
235
views
Objection to MVVM pattern is lack of IDE support - do any of the frameworks help with that?
Some of our developers don't like the commanding in MVVM because there is no support in VS2010 IDE to help you navigate from the Command binding in xaml to the actual code implementing the behavior. ...
4
votes
1
answer
882
views
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();
...
4
votes
2
answers
1k
views
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 ...
4
votes
2
answers
1k
views
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 ...
4
votes
1
answer
2k
views
Command routing for Keyboard shortcuts
Basically I want to create a keyboard shortcut which is valid within the scope of a window, and not just enabled when focus is within the control that binds it.
in more detail....
I have a window ...
4
votes
1
answer
690
views
What is the best approach to binding commands in a ViewModel to elements in the View?
Anyone who has tried to implement RoutedCommands in WPF using M-V-VM has undoubtedly run into issues. Commands (non-UI commands that is) should be implemented in the ViewModel. For instance if I ...
4
votes
2
answers
821
views
WPF: Trigger RoutedCommands implemented in UserControl nested inside a ContentControl
How can I trigger routed commands implemented inside a UserControl which is nested inside a ContentControl?
What I basically have is an outer view (derived from UserControl) which contains:
1) A ...
4
votes
2
answers
2k
views
How to debug commands
How do I debug a RoutedUICommand when the associated UIElement is disabled.
For example, consider the ContextMenu. Since it exists in a different VisualTree, a command written with the menu item ...
4
votes
1
answer
404
views
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 ...
3
votes
2
answers
5k
views
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 ...
3
votes
3
answers
2k
views
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 ...
3
votes
1
answer
1k
views
Executed gets not called after PreviewExecuted
Here's my code:
var commandBinding = new CommandBinding(ApplicationCommand.New);
commandBinding.PreviewExecuted += OnPreviewExecuted;
commandBinding.Executed += OnExecuted;
CommandBindings.Add(...
3
votes
1
answer
4k
views
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, ...
3
votes
2
answers
6k
views
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 ...
3
votes
1
answer
2k
views
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 = ...
3
votes
2
answers
342
views
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 ...
3
votes
1
answer
1k
views
RoutedCommands in Silverlight
Is it possible to use RoutedCommands such as ApplicationCommand.Copy, ApplicationCommand.Paste, etc in Silverlight 4 beta version ?
3
votes
1
answer
217
views
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 ...
3
votes
1
answer
360
views
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, ...
3
votes
2
answers
820
views
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 ...