Skip to content

Commit 5a767ab

Browse files
jamesmcroftSergio0694
authored andcommitted
Added docs for the RelayCommand and RelayCommand<T>
1 parent 433e2a1 commit 5a767ab

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

docs/mvvm/MigratingFromMvvmLight.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,81 @@ var isInDesignMode = ViewModelBase.IsInDesignModeStatic;
309309
// No direct replacement, remove
310310
```
311311

312+
## Migrating RelayCommand
313+
314+
The following steps focus on migrating your existing components which take advantage of the `RelayCommand` of the MvvmLight Toolkit.
315+
316+
The Windows Community Toolkit MVVM framework provides a [`RelayCommand`](RelayCommand) type that provides like-for-like functionality taking advantage of the `ICommand` System interface.
317+
318+
Below are a list of migrations that will need to be performed if being used in your current solution. Where a method or property isn't listed, there is a direct replacement with the same name in the MVVM Toolkit and there is no change required.
319+
320+
The first change here will be swapping using directives in your components.
321+
322+
```csharp
323+
// MvvmLight
324+
using GalaSoft.MvvmLight.Command;
325+
using Galasoft.MvvmLight.CommandWpf;
326+
327+
// Toolkit.Mvvm
328+
using Microsoft.Toolkit.Mvvm.Input;
329+
```
330+
331+
**Note** on `RelayCommand` constructors. MvvmLight uses weak references to establish the link between the command and the action called from the associated class. This is not required by the MVVM Toolkit implementation and if this optional parameter has been set to `true` in any of your constructors, this will be removed.
332+
333+
### RelayCommand Methods
334+
335+
#### RaiseCanExecuteChanged ()
336+
337+
The functionality of `RaiseCanExecuteChanged()` can be achieved with the MVVM Toolkit's `NotifyCanExecuteChanged()` method.
338+
339+
340+
```csharp
341+
// MvvmLight
342+
var command = new RelayCommand(this.OnCommand);
343+
command.RaiseCanExecuteChanged();
344+
345+
// Toolkit.Mvvm
346+
var command = new RelayCommand(this.OnCommand);
347+
command.NotifyCanExecuteChanged();
348+
```
349+
350+
## Migrating RelayCommand<T>
351+
352+
The following steps focus on migrating your existing components which take advantage of the `RelayCommand<T>` of the MvvmLight Toolkit.
353+
354+
The Windows Community Toolkit MVVM framework provides a [`RelayCommand<T>`](RelayCommand) type that provides like-for-like functionality taking advantage of the `ICommand` System interface.
355+
356+
Below are a list of migrations that will need to be performed if being used in your current solution. Where a method or property isn't listed, there is a direct replacement with the same name in the MVVM Toolkit and there is no change required.
357+
358+
The first change here will be swapping using directives in your components.
359+
360+
```csharp
361+
// MvvmLight
362+
using GalaSoft.MvvmLight.Command;
363+
using Galasoft.MvvmLight.CommandWpf;
364+
365+
// Toolkit.Mvvm
366+
using Microsoft.Toolkit.Mvvm.Input;
367+
```
368+
369+
**Note** on `RelayCommand<T>` constructors. MvvmLight uses weak references to establish the link between the command and the action called from the associated class. This is not required by the MVVM Toolkit implementation and if this optional parameter has been set to `true` in any of your constructors, this will be removed.
370+
371+
### RelayCommand<T> Methods
372+
373+
#### RaiseCanExecuteChanged ()
374+
375+
The functionality of `RaiseCanExecuteChanged()` can be achieved with the MVVM Toolkit's `NotifyCanExecuteChanged()` method.
376+
377+
```csharp
378+
// MvvmLight
379+
var command = new RelayCommand<string>(this.OnCommand);
380+
command.RaiseCanExecuteChanged();
381+
382+
// Toolkit.Mvvm
383+
var command = new RelayCommand<string>(this.OnCommand);
384+
command.NotifyCanExecuteChanged();
385+
```
386+
312387
## Migrating SimpleIoc
313388

314389
The [IoC](Ioc) implementation in the MVVM Toolkit takes advantage of existing .NET APIs through the `Microsoft.Extensions.DependencyInjection` library.
@@ -420,6 +495,16 @@ A note on `Register` methods throughout this migration. MvvmLight uses weak refe
420495

421496
Below are a list of migrations that will need to be performed if being used in your current solution.
422497

498+
The first change here will be swapping using directives in your components.
499+
500+
```csharp
501+
// MvvmLight
502+
using GalaSoft.MvvmLight.Messaging;
503+
504+
// Toolkit.Mvvm
505+
using Microsoft.Toolkit.Mvvm.Messaging;
506+
```
507+
423508
### Messenger Methods
424509

425510
#### Register<TMessage> ( object, Action<TMessage> )
@@ -659,7 +744,7 @@ IMessenger messenger = Messenger.Default;
659744
IMessenger messenger = Messenger.Default;
660745
```
661746

662-
## Message type migrations
747+
## Migrating message types
663748

664749
The message types provided in the MvvmLight toolkit are designed as a base for you as a developer to work with if needed.
665750

0 commit comments

Comments
 (0)