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
82
votes
5 answers

Command for WPF TextBox that fires up when we hit Enter Key

It is very easy to bind Buttons in WPF apps to Commands in a VIEWMODEL class. I'd like to achieve a similar binding for a TextBox. I have a TextBox and I need to bind it to a Command that fires up when I hit Enter while the TextBox is focused.…
Aryan SuryaWansi
  • 2,691
  • 10
  • 31
  • 33
72
votes
4 answers

ICommand MVVM implementation

So in this particular MVVM implementation I'm doing, I need several commands. I really got tired of implementing the ICommand classes one by one, so I came up with a solution, but I don't know how good it is, so the input of any WPF expert here will…
Carlo
  • 25,602
  • 32
  • 128
  • 176
52
votes
2 answers

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 I need to implement an ICommand? What about MVVM…
theSpyCry
  • 12,073
  • 28
  • 96
  • 152
47
votes
0 answers

Unit-Test project fails to build after installing .NET 4.5

I have a WPF solution in .NET 4.0 that includes a Unit Test project which tests the different commands used in the ViewModels. Everything was working fine, but then I installed .NET 4.5 and VS2012. Now when I try to build the solution I get error…
atiyar
  • 7,762
  • 6
  • 34
  • 75
45
votes
5 answers

Is Josh Smith's implementation of the RelayCommand flawed?

Consider the reference Josh Smith' article WPF Apps With The Model-View-ViewModel Design Pattern, specifically the example implementation of a RelayCommand (In Figure 3). (No need to read through the entire article for this question.) In general,…
Greg D
  • 43,259
  • 14
  • 84
  • 117
39
votes
3 answers

What is the actual task of CanExecuteChanged and CommandManager.RequerySuggested?

I got the following code from Josh Smith's MVVM tutorial. Can anyone provide a quick explanation of what this code actually does? public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove {…
Aryan SuryaWansi
  • 2,691
  • 10
  • 31
  • 33
34
votes
7 answers

CommandManager.InvalidateRequerySuggested() isn't fast enough. What can I do?

Short Version Calls to CommandManager.InvalidateRequerySuggested() take far longer to take effect than I would like (1-2 second delay before UI controls become disabled). Long Version I have a system where I submit tasks to a background-thread based…
Rob
  • 25,984
  • 32
  • 109
  • 155
33
votes
4 answers

Pass command parameter to method in ViewModel in WPF?

I am trying to pass CommandParameter to the method in my ViewModel. How to do this? private void Open(object sender) { if (sender==this.objMainWindow.btnHistory) { objMainWindow.Container.Child = objHistory; } if (sender ==…
Mahsa
  • 477
  • 1
  • 5
  • 9
26
votes
2 answers

CanExecuteChanged event of ICommand

Icommand contains two methods and one event. What the two methods do is clear, but I can’t understand what the event does that is provided in ICommand. When is the CanExecuteChanged event raised? The below explanation is on MSDN but I can’t…
Pritesh
  • 3,208
  • 9
  • 51
  • 70
21
votes
2 answers

Pass command parameter from the xaml

I try to do something like this:
Maya
  • 989
  • 4
  • 12
  • 19
21
votes
7 answers

binding a command inside a listbox item to a property on the viewmodel parent

I've been working on this for about an hour and looked at all related SO questions. My problem is very simple: I have HomePageVieModel: HomePageVieModel +IList AllNewsItems +ICommand OpenNews My markup:
gideon
  • 19,329
  • 11
  • 72
  • 113
20
votes
2 answers

Multiple command parameters wpf button object

How can I send multiple parameters from Button in WPF? I am able to send single parameter which is value of TextBox properly. Here is the code. XAML
Mandar Jogalekar
  • 3,199
  • 7
  • 44
  • 85
20
votes
2 answers

What replaces CommandManager in WinRT?

I'm getting started with Metro style applications (I know we're not supposed to call it Metro, but I can never remember what it's supposed to be called...), and I'm implementing a DelegateCommand class for use in MVVM. In WPF, the…
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
17
votes
4 answers

How to cancel window closing in MVVM WPF application

How can I cancel exiting from particular form after Cancel button (or X at the top right corner, or Esc) was clicked? WPF:
17
votes
2 answers

How can I pass the event argument to a command using triggers?

So I have a simple setup, an autocompletebox with its Populating event that I want to bind to a command. I use clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity (is there a better namespace for doing this?) It's not…
Trident D'Gao
  • 18,973
  • 19
  • 95
  • 159
1
2 3
32 33