Questions tagged [icommand]

Interface for MVVM scenarios in Silverlight and WPF to bind commands from models to controls (Buttons).

Typically objects implement this interface to enable method calls on the objects through the use of XAML bindings. This is particularly useful in Model-View-ViewModel (MVVM) scenarios, as it allows models to expose commands to which controls such as buttons can be bound to without requiring additional code

481 questions
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

How to bind a Command to double-click on a row in DataGrid

I have developed a WPF UserControl that is intended to be used as a pick list as follows: A DataGrid bound to a CollectionView of entities (e.g. of Employees) A TextBox above the DataGrid that can be used to filter items displayed in the…
Joe
  • 122,218
  • 32
  • 205
  • 338
9
votes
2 answers

WPF/MVVM: Disable a Button's state when the ViewModel behind the UserControl is not yet Initialized?

I have a DocumentListView.Xaml with a ListBox and 3 Buttons. Behind that UserControl sits a DocumentListViewModel with 3 Buttons and their Command Property bound to 3 RelayCommands. I have 3 Controller like AdministrationController,…
Elisabeth
  • 20,496
  • 52
  • 200
  • 321
9
votes
1 answer

What comes first - Command or EventHandler?

In context of Microsoft's MVVM pattern and its Commanding/Event Handling aspects consider I am doing both binding a Command to a Control (say a Button) and subscribing to the control's Click event. Is there any general rule what action takes place…
marc wellman
  • 5,808
  • 5
  • 32
  • 59
8
votes
3 answers

WPF and MVVM. Binding Events

I'm developing a WPF application with the MVVM pattern, RelayCommand, etc. I read a lot on this question but I am not clear as to: All I want to do is move a shape, like an ellipse, for example, and capture its final position, to put in the…
Dani O.
  • 89
  • 1
  • 1
  • 3
8
votes
1 answer

Is the common implementation of RelayCommand violating the MVVM pattern?

A very common implementation of RelayCommand seems to include the following lines: public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { …
Tim Pohlmann
  • 4,140
  • 3
  • 32
  • 61
7
votes
2 answers

Are there any performance implications with CanExecuteCommand?

What are the performance implications of using the CanExecuteCommand of the ICommand object. Is the method executed over and over again? I need to iterate through a collection of about 200 objects based on which its decided whether the button bound…
ganeshran
  • 3,512
  • 7
  • 41
  • 69
7
votes
3 answers

WPF MVVM - Unit Testing a command - Private vs Public methods?

Basically, If I use MVVM and expose public ICommands, should my delegates be public or private?
michael
  • 14,844
  • 28
  • 89
  • 177
7
votes
8 answers

How to close a ChildWindow with Cancel button using MVVM Light Toolkit

I'm new to MVVM and trying to figure out how to close a ChildWindow with the traditional Cancel button using MVVM Light Toolkit. In my ChildWindow (StoreDetail.xaml), I have :
7
votes
1 answer

MVVM Call Command from CommandBinding

I wanted to bind a CommandBinding to a ViewModel ICommand, this way, when the user hits Delete I can trigger my ViewModel's delete logic. The only way I know how to do it is in code behind, with this:
Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
7
votes
1 answer

Button Command CanExecute not called when property changed

I have a form with a textbox and a button. When that textbox has it's value changed, the button command doesn't call the CanExecute method of it's command. The command parameter is set but doesn't seem to change. After load the window, the button…
Thiago Romam
  • 439
  • 4
  • 14
7
votes
2 answers

Saving a WPF canvas as an image following MVVM Pattern

I have a canvas, e.g. similar to this solution or many others using the ItemsControl. Now I want a button which should be bound to an ICommand. This command should call a method of ViewModel class which can save the image. The saving method is…
Rolfi
  • 452
  • 5
  • 13
6
votes
4 answers

What is the reason for ICommand in Mvvm?

In application using a mvvm-approach it's pretty common that the ViewModel provides one or more Command-properties. These properties often have the type ICommand or DelegateCommand or something like that. I don't understand why we need such an…
Ranga B.
  • 627
  • 10
  • 20
6
votes
1 answer

How do I pass Nullable value to CommandParameter?

I am using the MVVM Light library. From this library I use RelayCommand to define commands with an argument of type T. Now I have defined a RelayCommand that requires an argument of type Nullable: private RelayCommand
Chris
  • 323
  • 2
  • 12
6
votes
2 answers

Why is my ICommand.CanExecute(object) parameter null when I set CommandParameter to some Binding, but non-null when I set it to some static value?

I'm learning ICommands in WPF and I ran into a problem with some simple code. I have a Button with a Command. If I set the command parameter to a static value like this, CommandParameter="100", the value of the parameter argument in CanExecute is…
user2023861
  • 8,030
  • 9
  • 57
  • 86
1 2
3
32 33