3

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

Dependencies

I installed/uninstalled .Net Core and restarted visual studio 2019 preview but without success. OS is Windows 10 x64.

    public class RelayCommand : ICommand
        {

            readonly Action<object> _execute;
            readonly Predicate<object> _canExecute;


            public RelayCommand(Action<object> execute) : this(execute, null) { }
            public RelayCommand(Action<object> execute, Predicate<object> canExecute)
            {
                _execute = execute ?? throw new 
                ArgumentNullException("execute"); _canExecute = canExecute;
            }

            [DebuggerStepThrough]
            public bool CanExecute(object parameter)
            {
                return _canExecute == null ? true : _canExecute(parameter);
            }
            public event EventHandler CanExecuteChanged 
            {
                add { CommandManager.RequerySuggested += value; }
                remove { CommandManager.RequerySuggested -= value; }
            }
            public void Execute(object parameter) { _execute(parameter); }

    }
Sorush
  • 3,275
  • 4
  • 28
  • 42

2 Answers2

2

A bit late but someone else may benefit.

This is for targeting .NET Core 3.0 Preview 6

I installed via NuGet the following into my WPF UI project:

Microsoft.NETCore.Platforms Version="3.0.0-preview6.19303.8"

Microsoft.NETCore.Targets Version="3.0.0-preview6.19303.8"

Microsoft.WindowsDesktop.App Version="3.0.0-preview6-27804-01"

System.Windows.Input.CommandManager is then available.

You should already have SDK namely Microsoft.NETCore.App (3.0.0-preview6-27804-01)

Col
  • 36
  • 2
1

I used a Class Library in my WPF application for the Commands, but the CommandManager is not there, even though the Documentation states it is in .NET Core and it's placed in the System.Windows.Input.

Thanks to Col I was able to get it to work by change the Output type from Class Library to Windows Application:
Class Library Windows Application

Right click your project > Properties > Application

Hypenate
  • 1,907
  • 3
  • 22
  • 38