Questions tagged [relaycommand]

RelayCommand is an implementation of the .NET ICommand interface made and described by WPF expert Josh Smith.

289 questions
5
votes
1 answer

Button hold down to repeat commands

I have a button in my WPF project and I want to it execute the same command over and over when I hold the button down. I could use RepeatButton but my preference would be for the command to execute again as soon as it is done running (in its own…
AClark
  • 47
  • 5
5
votes
1 answer

Why is param in this lambda expression?

The MSDN magazine article by Josh Smith on MVVM contains a lambda expression I don't completely understand. What is the purpose of param in this code? _saveCommand = new RelayCommand(param => this.Save(), param => this.CanSave…
DeveloperDan
  • 4,626
  • 9
  • 40
  • 65
4
votes
2 answers

RelayCommand RaiseCanExecuteChanged() fails

I am using a couple of Buttons bound to RelayCommands initialized with CanExecute delegates. RelayCommand DeleteCommand; bool CanDelete() { return BoolProp1 && BoolProp2; } ... DeleteCommand = new RelayCommand(Delete, CanDelete); BoolProp1…
Jacek Gorgoń
  • 3,206
  • 1
  • 26
  • 43
4
votes
2 answers

Pass CommandParameter to Command in Silverlight using MVVM

I'm just learning Silverlight and looking at MVVM and Commanding. Ok, so I have seen the basic RelayCommand implementation: public class RelayCommand : ICommand { private readonly Action _handler; private bool _isEnabled; public…
Mike
  • 6,149
  • 5
  • 34
  • 45
4
votes
1 answer

Cannot find GalaSoft.MvvmLight.CommandWpf namespace in MVVM Light 5.2.0.37222

I just tried to update one of my WPF projects from MVVM Light 4.2.30 to 5.2. After that I noticed that my RelayCommands do not fire their CanExecute methods anymore. After a quick search I found several articles that explain the problem and suggest…
Ralf
  • 293
  • 5
  • 15
4
votes
1 answer

Can't pass a single parameter to lambda function in MVVM Light Toolkit's RelayCommand

I don't know if there's a difference between Josh Smith's and Laurent Bugnion's implementations of RelayCommand or not, but everywhere I've looked, it sounds like the Execute portion of RelayCommand can take 0 or 1 parameters. I've only been able…
Dave
  • 14,618
  • 13
  • 91
  • 145
4
votes
2 answers

RelayCommand Memory leak

I am looking for an implementation of RelayCommand. The original implementation that I considered was the classic one (lets call it implementation A) public class RelayCommand : ICommand { private readonly Predicate canExecute; …
Kobi Hari
  • 1,259
  • 1
  • 10
  • 25
4
votes
3 answers

CanExecute() not enabling button when condition is met

I have a very simple application with a TextBox and a Button. When the text entered into the TextBox exceeds 5 characters in length, the button will be enabled. Here is the code for my ViewModel: private string _text { get; set; } public string…
user3761858
  • 231
  • 2
  • 6
  • 13
4
votes
1 answer

Binding CommandParameter on ItemsControl Tap event

I'm using an ItemsControl, and I want to identify which item was selected on the Tap command. My xaml is defined here:
earthling
  • 5,084
  • 9
  • 46
  • 90
3
votes
3 answers

Best / neatest way to declare RelayCommands

I've been trying to find a nice neat and succinct way to declare RelayCommands in my ViewModels. The best I can come up with is: public class MyViewModel { public ICommand StopCommand { get; private set; } public MyViewModel() { …
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
3
votes
1 answer

object sender is always null in RelayCommand

I am using RelayCommand to handle a button click, I need to get the sender parameter but it is always null, any idea why? ViewModel.cs private RelayCommand _expandClickCommand; public ICommand ExpandClickCommand { get { …
Eamonn McEvoy
  • 8,876
  • 14
  • 53
  • 83
3
votes
2 answers

Moving RelayCommand (CommandManager) from .Net Framework to .NET Core v3.0.100-preview3

My RelayCommand includes the implementation of CommandManager which is not known by .net core 3 preview 3. However, Microsoft says the it is available: see here I installed/uninstalled .Net Core and restarted visual studio 2019 preview but without…
Sorush
  • 3,275
  • 4
  • 28
  • 42
3
votes
4 answers

Command binding in multiwindow WPF app

My application can have multiple designer windows. Each window constitutes of several user controls which communicates dynamically with the help of RelayCommands. I created the following class as the backbone of the commanding infrastructure. public…
Jimmy
  • 3,224
  • 5
  • 29
  • 47
3
votes
1 answer

How do I test Relaycommand?

I'm reading this MSDN Article about MVVM. I'm currently looking at the RelayCommand in figure #15. Pretend I wanted to test this SaveCommand. How would I do that? I'm using NUnit and Rhino Mocks 3.6
Ols1
  • 321
  • 3
  • 15
3
votes
1 answer

Same method for multiple controls when using Caliburn.Micro

In WPF MVVM application, I need same functionality for multiple controls - for example certain button does same thing as certain menu item. It is piece of cake with MVVM Light's RelayCommand, but I am now using Caliburn.Micro, where almost…
Ondřej
  • 1,645
  • 1
  • 18
  • 29
1 2
3
19 20