This project has moved and is read-only. For the latest updates, please go here.


Relay Command CanExecute() not working in WinRT for refence types


  • create a generic command that receives some class
  • bind this command to XAML without value for CommandParameter
    In previous version CommandParameter without value leads to null value in code. Now command just not executing.
    Is think reference types as command parameter should accept NULL.
In PCL version RelayCommandGeneric.cs, public bool CanExecute(object parameter):
                if (parameter == null
                    && typeof(T).GetTypeInfo().IsValueType)
                    && typeof(T).IsValueType)
This is covering value type check only, no reference type check.
Closed Feb 15, 2015 at 6:13 PM by lbugnion


vunder wrote Oct 23, 2014 at 2:14 PM

With current behavior we cannot use simple pattern to work with objects: null value - create new object, not null value - edit existing object. With current RelayCommand<T> we have to create different commands for object creating and object editing.

vunder wrote Oct 23, 2014 at 2:18 PM

My proposal: replace condition with next code:
                if (!
|| parameter != null)

lbugnion wrote Oct 23, 2014 at 2:53 PM

I get what you say. The null check was introduced to solve another issue where the command code was attempting to cast the null parameter and was failing. Let me think over your proposal and make sure that it doesn't break anything else.

Thanks for following up and opening a new issue rather than writing on the other one, appreciated.


jackomo wrote Oct 23, 2014 at 3:42 PM

I experience the same issue in a normal .NET 4.5 application (no WinRT, but VB.NET).

This is critical to me because I cannot update to the latest version of MVVM Light V5 to get other bug fixes...

vunder wrote Oct 24, 2014 at 5:45 AM

You may copy-paste code from Execute method. It contains null-check and value type check

lbugnion wrote Feb 6, 2015 at 3:27 PM

Fixed in V5.1 (upcoming)

lbugnion wrote Feb 6, 2015 at 5:13 PM

DLLs are available here:

Nuget will be updated ASAP.