Binds a RoutedCommand to the event handlers that implement the command.
Questions tagged [commandbinding]
201 questions
139
votes
6 answers
WPF - How to force a Command to re-evaluate 'CanExecute' via its CommandBindings
I have a Menu where each MenuItem in the hierarchy has its Command property set to a RoutedCommand I've defined. The associated CommandBinding provides a callback for the evaluation of CanExecute which controls the enabled state of each…

Drew Noakes
- 300,895
- 165
- 679
- 742
67
votes
7 answers
How to bind Close command to a button
The easiest way is to implement ButtonClick event handler and invoke Window.Close() method, but how doing this through a Command binding?

iLemming
- 34,477
- 60
- 195
- 309
37
votes
4 answers
WPF DataGrid: CommandBinding to a double click instead of using Events
I know how to use the MouseDoubleClick event with my DataGrid to grab the selectedvalue, but how would one go about using command bindings instead? That way my ViewModel can handle the logic.
So far I have the following:

myermian
- 31,823
- 24
- 123
- 215
35
votes
2 answers
Bind command to Loaded event of view
I am trying to get a method to run when a view has finished loading. I have tried to bind a command to the Loaded event in the view but it fails to run. The inner exception that is thrown is
'Provide value on 'System.Windows.Data.Binding' threw an…

scott lafoy
- 1,001
- 1
- 13
- 30
33
votes
9 answers
WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?
(Note - this is a re-post as my first question got posted under wrong headline: Here Sorry!)
I have a standard WPF treeview and have bound items to view model classes.
I now wish to handle behaviour when items are double-clicked (opening documents…

Anders Juul
- 2,407
- 3
- 34
- 56
32
votes
4 answers
Using the parent's DataContext (WPF - Dynamic Menu Command Binding)
I looked over this web and google and the solutions didn't work for me.
I have a command on the ViewModel of a UserControl. Well, The usercontrol have a ItemsControl binded to a ObservableCollection. Inside the DataTemplate of the…

Jesus Rodriguez
- 11,918
- 9
- 64
- 88
31
votes
6 answers
WPF: How to bind a command to the ListBoxItem using MVVM?
I have just started learning MVVM. I've made the application from scratch by following this MVVM tutorial (I highly recommend it to all MVVM beginners out there). Basically, what I have created so far is a couple of text boxes where user adds his or…

Boris
- 9,986
- 34
- 110
- 147
21
votes
5 answers
WPF: Execute a Command Binding in a search field when pressing the enter button
I have a search field in my WPF app with a search button that contains a command binding. This works great, but how can i use the same command binding for the text field when pressing enter on the keyboard? The examples I have seen are all using the…

code-zoop
- 7,312
- 8
- 47
- 56
15
votes
3 answers
Enable command binding for TextBlock
I am developing a WPF application, and have a TextBlock which I want to use command binding to trigger a command on when clicked. What's the best way to achieve this?
The TextBlock-control does not have a Command property, but it does have a…

stiank81
- 25,418
- 43
- 131
- 202
14
votes
1 answer
Receiving CommandParameter Value in MVVM
I am binding my command like:
Here, I also bind its CommandParameter property, now how to fetch its value from NextCommand.
public ICommand NextCommand
…
Naresh Goradara
14
votes
6 answers
How to Bind a Command in WPF
Sometimes we used complex ways so many times, we forgot the simplest ways to do the task.
I know how to do command binding, but i always use same approach.
Create a class that implements ICommand interface and from the view model i create new…

Manvinder
- 4,495
- 16
- 53
- 100
11
votes
4 answers
How to fire a Command when a window is loaded in wpf
Is it possible to fire a command to notify the window is loaded.
Also, I'm not using any MVVM frameworks (Frameworks in the sense, Caliburn, Onxy, MVVM Toolkit etc.,)

Prince Ashitaka
- 8,623
- 12
- 48
- 71
9
votes
2 answers
Can I have multiple CommandBindings for the same Command on the same control?
I have a UserControl that adds a CommandBinding to it's CommandBindings collection to handle a specific Command. Later I use this control in a window and want to add another binding to that same control to add additional behavior. The problem…

jpierson
- 16,435
- 14
- 105
- 149
9
votes
2 answers
Application Level shortcut keys in WPF
In WPF application I am currently trying to bind a Command to launch a calculator Tool form any where in the application using shortcut keys, I have created a command but not getting how to map commands and shortcut keys to create universal shortcut…

Nadeem Shukoor
- 323
- 2
- 4
- 15
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