relaycommand

MVVM Routed and Relay Command

What is the Difference between the RoutedCommand and RelayCommand ? When to use RoutedCommand and when to use RelayCommand in MVVM pattern ? ...

RelayCommand lambda syntax problem

I am applying the MVVM pattern per Josh Smith and having difficulty. I've been researching the problem here and can't seem to get the syntax quite right. The code below looks to me like it follows the required syntax, but Visual Studio reports error "Delegate 'System.Action' does not take '2' arguments" on the line indicated. Can some...

Proper way in MVVM to direct the handling of a RelayCommand to a view model parent.

I'm very new to MVVM and even WPF to some degree so bear with me... I've got a MVVM application that has a main window, containing a viewmodel instance of different types depending on application state. One of these viewmodels is an options screen which contains a button to restart the application and log into the database as a differe...

.NET delegate equality?

I think this is the question, anyway. I am using a RelayCommand, which decorates an ICommand with two delegates. One is Predicate for the _canExecute and the other is Action for the _execute method. ---Background motivation -- The motivation has to do with unit testing ViewModels for a WPF presentation. A frequent pattern is that I hav...

wpf mvvm equality

I would like to use an MVVM in a WPF project I'm working on, including the use of RelayCommands (aka DelegateCommands). I'm running into an interesting but frustration problem in implementing equality for my ViewModels, outlined here. I have a base class in my ViewModel hierarchy which examines all properties reflectively as part of its ...

Is Josh Smith's implementation of the RelayCommand flawed?

Consider the reference article, specifically the example implementation of a RelayCommand (In Figure 3). (No need to read through the entire article for this question.) In general, I think the implementation is excellent, but I have a question about the delegation of CanExecuteChanged subscriptions to the CommandManager's RequerySugges...

CanExecute on RelayCommand<T> not working

...

How to implement menuitems that depend on current selection in WPF MVVM explorer-like application

I am new to WPF and MVVM, and I am working on an application utilizing both. The application is similar to windows explorer, so consider an app with a main window with menu (ShellViewModel), a tree control (TreeViewModel), and a list control (ListViewModel). I want to implement menu items such as Edit -> Delete, which deletes the curre...

WPF relaycommand from usercontrol

Hi, I'm new to WPF and in the spirit of trying to do things the correct way have tried to implement MVVM in my application. I've made use of the frequently mentioned article by Josh Smith, and apart from making me realise how little I know, it has left me a little stumped. Specifically, I have a page that uses the RelayCommand object t...

Reuse controls inside a usercontrol

I have a UserControl UserControl1 and a button inside the UserControl1. And I have a UserControl1ViewModel that has an ICommand property for the button. Using this command I need to call a method outside(from other VMs or VM of the MainWindow) the VM. What is the best practice for this? ...

RelayCommand sender from ItemsControl item

I've been using MVVM's RelayCommand with success to bind actions to XAML, but I'm having a small problem with my ItemsControl. <ItemsControl ItemsSource="{Binding Devices}" > <ItemsControl.ItemTemplate> <DataTemplate> <Grid Width="100" Margin="4" > <Button Command="{Binding Pat...

How do you send in the LayoutRoot into a RelayCommand via a EventToCommand?

Grid example with the trigger: <Grid x:Name="LayoutRoot" DataContext="{Binding ProjectGrid, Source={StaticResource Locator}}"> <i:Interaction.Triggers> <i:EventTrigger EventName="Loaded"> <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding LoadedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/> </i:EventTrigger> </...

Passing event args and sender to the RelayCommand

How do you get event sender when using RelayCommand? ...

Programatic re-evalutation of MVVM command's "can execute" state

Hello! I'm writing a WPF application using the MVVM pattern, based on the following article: WPF Apps With The Model-View-ViewModel Design Pattern I have two buttons on my View with the buttons' "Command" property bound (with data binding) to a given instance of the RelayCommand class (see "Figure 3 The RelayCommand Class" from the art...

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 to get it to work with 0. When I try something like: public class Test { public Relay...

Simplifying RelayCommand/DelegateCommand in WPF MVVM ViewModels

If you're doing MVVM and using commands, you'll often see ICommand properties on the ViewModel that are backed by private RelayCommand or DelegateCommand fields, like this example from the original MVVM article on MSDN: RelayCommand _saveCommand; public ICommand SaveCommand { get { if (_saveCommand == null) { ...

Does RelayCommand, or passing an Action<T>, behave differently when the method is from an interface?

I think this is my overall .NET inexperience speaking here, but I cannot figure out why this is happening to me. My Model ImportManys an interface called ISystemSetupEditor, and in this case I have a couple of parts that Export that interface. In the application's ViewModel, I have a method that creates a menu, and iterates over the IE...

Using IsDirty with ICommands

I am trying to use an IsDirty flag to control CanExecute and Navigational controls during an object edit. The problem is that in order for this to work I think I have to use onPropertyChanged for my IsDirty method so that my controls get change notification.(I want some controls to be disabled when my object IsDirty) Unfortunately I ge...

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 ); Translated to my preferred language VB it's: Dim saveAction as New Action(Of Object)(Addr...