Questions tagged [icommand]
Interface for MVVM scenarios in Silverlight and WPF to bind commands from models to controls (Buttons).
                                	
	icommand
    
                            
                        
                    
            487
            questions
        
        
            84
            votes
        
        
            5
            answers
        
        
            88k
            views
        
    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 ...
            
        
       
    
            73
            votes
        
        
            4
            answers
        
        
            159k
            views
        
    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 ...
            
        
       
    
            56
            votes
        
        
            1
            answer
        
        
            3k
            views
        
    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.
...
            
        
       
    
            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 ...
            
        
       
    
            45
            votes
        
        
            5
            answers
        
        
            14k
            views
        
    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 ...
            
        
       
    
            39
            votes
        
        
            3
            answers
        
        
            15k
            views
        
    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 { ...
            
        
       
    
            35
            votes
        
        
            4
            answers
        
        
            173k
            views
        
    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....
            
        
       
    
            34
            votes
        
        
            7
            answers
        
        
            23k
            views
        
    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 ...
            
        
       
    
            27
            votes
        
        
            2
            answers
        
        
            33k
            views
        
    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?
...
            
        
       
    
            22
            votes
        
        
            2
            answers
        
        
            44k
            views
        
    Pass command parameter from the xaml
                I try to do something like this:
<DataGrid Name="myGrid" ItemSource="{Binding Path=MyCollection}">
   <DataGrid.ContextMenu>
       <ContextMenu>
          <MenuItem 
            ...
            
        
       
    
            21
            votes
        
        
            7
            answers
        
        
            31k
            views
        
    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<NewsItem> AllNewsItems
+...
            
        
       
    
            21
            votes
        
        
            2
            answers
        
        
            6k
            views
        
    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 ...
            
        
       
    
            20
            votes
        
        
            2
            answers
        
        
            44k
            views
        
    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
<TextBox Grid.Row="1" Height="23" ...
            
        
       
    
            17
            votes
        
        
            2
            answers
        
        
            22k
            views
        
    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 ...
            
        
       
    
            17
            votes
        
        
            4
            answers
        
        
            35k
            views
        
    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:
<Window
  ...
  x:Class="MyApp.MyView"
  ...
/>
  <Button Content="...
            
        
       
    
            15
            votes
        
        
            3
            answers
        
        
            6k
            views
        
    How do I unit test an async ICommand in MVVM?
                I've been Googling and even Bing-ing and I haven't come up with anything that is satisfying.
I have a ViewModel which has some commands, such as: SaveCommand, NewCommand and DeleteCommand. My ...
            
        
       
    
            14
            votes
        
        
            3
            answers
        
        
            3k
            views
        
    Translation of C# ActionCommand:ICommand into VB.net
                I found a C# class ActionCommand, that implements ICommand and bases on delegates for Execute and CanExecute. Looks perfect for me so far.
  public class ActionCommand : ICommand
  {
    private ...
            
        
       
    
            14
            votes
        
        
            6
            answers
        
        
            63k
            views
        
    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 ...
            
        
       
    
            14
            votes
        
        
            1
            answer
        
        
            15k
            views
        
    How to enable a Button with its CanExecute method
                I am developing an application in WPF using MVVM, but I am stuck with the ICommand objects.
I have a windows which contains some buttons, so, I bind them to their respective ICommand in XAML as below:...
            
        
       
    
            13
            votes
        
        
            3
            answers
        
        
            19k
            views
        
    wpf command parameter from other object
                I'm wondering how to mark up the XAML for the following.  I have a view model with an object based on ICommand.
I have a form with a textbox and a button.  The button is hooked to the ICommand object ...
            
        
       
    
            13
            votes
        
        
            5
            answers
        
        
            18k
            views
        
    WPF ViewModel Commands CanExecute issue
                I'm having some difficulty with Context Menu commands on my View Model.
I'm implementing the ICommand interface for each command within the View Model, then creating a ContextMenu within the ...
            
        
       
    
            13
            votes
        
        
            2
            answers
        
        
            7k
            views
        
    Bind a button to a command (Windows Phone 7.5)
                I'm working on my windows-phone app which uses some simple data binding. I've already created a app which was based on the MvvM programming method.The app i'm currently working on also works by MvvM ...
            
        
       
    
            12
            votes
        
        
            5
            answers
        
        
            17k
            views
        
    Relay Command can execute and a Task
                i want to start a task when a relay command is called, however i want to disable the button as long as that task is running
take this example
private ICommand update;
public ICommand Update
        {...
            
        
       
    
            12
            votes
        
        
            1
            answer
        
        
            12k
            views
        
    Async ICommand implementation
                I'm facing a strange behavior by my asny ICommand implementation when I tried to disable the command while it's executing by default (even when no CanExecute predicate was passed to it).
public bool ...
            
        
       
    
            11
            votes
        
        
            6
            answers
        
        
            18k
            views
        
    WPF: TreeViewItem bound to an ICommand
                I am busy creating my first MVVM application in WPF. 
Basically the problem I am having is that I have a TreeView (System.Windows.Controls.TreeView) which I have placed on my WPF Window, I have ...
            
        
       
    
            11
            votes
        
        
            7
            answers
        
        
            19k
            views
        
    C#/WPF: KeyBinding not triggering Command
                I have declared <InputBindings>
<UserControl.InputBindings>
    <KeyBinding Key="C" Modifiers="Ctrl" Command="{Binding CopyImageCommand}" />
    <KeyBinding Key="V" Modifiers="...
            
        
       
    
            10
            votes
        
        
            3
            answers
        
        
            17k
            views
        
    ICommand Dependency Property
                I have an UserControl with a button inside. This button needs to add some items to a Grid that's inside said UC. I'm aware I can do this with a Click event. 
The issue here is I am using MVVM and ...
            
        
       
    
            10
            votes
        
        
            3
            answers
        
        
            6k
            views
        
    ICommand.CanExecute being passed null even though CommandParameter is set
                I have a tricky problem where I am binding a ContextMenu to a set of ICommand-derived objects, and setting the Command and CommandParameter properties on each MenuItem via a style:
<ContextMenu
   ...
            
        
       
    
            10
            votes
        
        
            1
            answer
        
        
            36k
            views
        
    WPF & MVVM: Get values from textboxes and send it to ViewModel
                I'm trying to get the value of two Texboxes (I'm simulating a login window) when I press a button. The command assigned in the button fires correctly, but I don't know how to get the value of the ...
            
        
       
    
            10
            votes
        
        
            4
            answers
        
        
            501
            views
        
    What is the real advantage of keeping code out of the XAML code behind?
                There is a lot of effort in the Silverlight community to keep a XAML's code behind file as free of code as possible. What is the real motivation behind this?  
For example, what is the advantage of ...
            
        
       
    
            9
            votes
        
        
            2
            answers
        
        
            6k
            views
        
    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 ...
            
        
       
    
            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
        
        
            18k
            views
        
    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 ...
            
        
       
    
            9
            votes
        
        
            1
            answer
        
        
            2k
            views
        
    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.
...
            
        
       
    
            8
            votes
        
        
            3
            answers
        
        
            15k
            views
        
    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 ...
            
        
       
    
            8
            votes
        
        
            1
            answer
        
        
            2k
            views
        
    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;
    }
 ...
            
        
       
    
            7
            votes
        
        
            3
            answers
        
        
            8k
            views
        
    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?
            
        
       
    
            7
            votes
        
        
            1
            answer
        
        
            9k
            views
        
    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 ...
            
        
       
    
            7
            votes
        
        
            2
            answers
        
        
            3k
            views
        
    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 ...
            
        
       
    
            7
            votes
        
        
            2
            answers
        
        
            3k
            views
        
    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 ...
            
        
       
    
            7
            votes
        
        
            8
            answers
        
        
            6k
            views
        
    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 :
<Button x:Name="...
            
        
       
    
            7
            votes
        
        
            1
            answer
        
        
            3k
            views
        
    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:...
            
        
       
    
            6
            votes
        
        
            4
            answers
        
        
            6k
            views
        
    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 ...
            
        
       
    
            6
            votes
        
        
            3
            answers
        
        
            5k
            views
        
    Updated title: Why ICommand.CanExecute is getting called all the time, instead of working like an event?
                I am adopting MVVM pattern in WPF and have learned the use of Command. But in my implementation, the delegate I assigned to implement CanExecute is always called. I mean if I put a break point inside ...
            
        
       
    
            6
            votes
        
        
            2
            answers
        
        
            8k
            views
        
    MVVM (ICommand) in Silverlight
                Please, don't judge strictly if this question was discussed previously or indirectly answered in huge nearby prism and mvvm blogs. 
In WPF implementation of RelayCommand or DelegateCommand classes ...
            
        
       
    
            6
            votes
        
        
            2
            answers
        
        
            13k
            views
        
    MVVM Execute Command on ViewModel from other ViewModel
                I'm struggling for about 14 days now with a simple task: In database, I have definitions for hardware categories. For example :
HDD
Internal
External
Flash
This list is in database defined like ...
            
        
       
    
            6
            votes
        
        
            4
            answers
        
        
            4k
            views
        
    What is the recommended way to open a new window using MVVM in WPF
                Hello everyone and thanks in advance for your time.
I'm currently learning MVVM using WPF for a small Biz App that I'm writing. I have read a lot of articles about the MVVM pattern and found that one ...
            
        
       
    
            6
            votes
        
        
            2
            answers
        
        
            4k
            views
        
    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 ...
            
        
       
    
            6
            votes
        
        
            1
            answer
        
        
            2k
            views
        
    Dotfuscator CE Build Error: External type not found System.Windows.Input.ICommand,PresentationCore
                I have an application targeting the .NET Framework 4.0.  It builds and runs fine but I cannot get it to compile in Dotfuscator CE and they will not support it since it is CE.  I am stuck.
Dotfuscator ...
            
        
       
    
            6
            votes
        
        
            2
            answers
        
        
            3k
            views
        
    RelayCommand in C#
                I am learning MVVM for C# Silverlight development from 
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
and I am confused about the RelayCommand class mentioned in the context. The code is:
...