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
15
votes
3 answers

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 SaveCommand executes a save to a file operation, which I…
Peter pete
  • 704
  • 1
  • 7
  • 17
14
votes
3 answers

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 readonly Action _executeHandler; private…
Markus
  • 4,487
  • 3
  • 41
  • 51
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
14
votes
1 answer

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

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 resources of the View (MainWindow), and using a…
LiamV
  • 1,138
  • 1
  • 14
  • 21
13
votes
3 answers

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 via Command="{Binding MyButtonInViewModel}". What…
DRapp
  • 47,638
  • 12
  • 72
  • 142
13
votes
2 answers

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 method. Because i want to keep my code behind as…
Bart Teunissen
  • 1,420
  • 5
  • 20
  • 43
11
votes
7 answers

C#/WPF: KeyBinding not triggering Command

I have declared
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
11
votes
5 answers

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 { get { if…
FPGA
  • 3,525
  • 10
  • 44
  • 73
10
votes
1 answer

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 CanExecute(object parameter) { if…
user3292642
  • 711
  • 2
  • 8
  • 32
10
votes
4 answers

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 using a command instead of an event handler? If I…
Matt Greer
  • 60,826
  • 17
  • 123
  • 123
10
votes
3 answers

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:
devios1
  • 36,899
  • 45
  • 162
  • 260
10
votes
3 answers

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 altering data outside their corresponding ViewModel…
Xanagandr
  • 723
  • 2
  • 9
  • 19
10
votes
6 answers

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 decide that I will bind to a ReadOnlyCollection of…
Richard
  • 3,207
  • 5
  • 30
  • 35
10
votes
1 answer

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 textboxes to do the "login". This is my…
Oscar Mateu
  • 789
  • 3
  • 10
  • 22
1
2
3
32 33