I have a DelegateCommand class and within it 2 constructors. When I pass my property to the constructor of that class I get an error message that says:
Error 1 The best overloaded method match for 'QMAC.ViewModels.DelegateCommand.DelegateCommand(System.Action<object>)' has some invalid arguments
Error 2 Argument 1: cannot convert from 'System.Windows.Input.ICommand' to 'System.Action<object>'
For my DelegateCommand, here is what I have (without comments to keep it short):
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
namespace QMAC.ViewModels
{
class DelegateCommand : ICommand
{
private Action<object> _execute;
private Predicate<object> _canExecute;
public DelegateCommand(Action<object> execute) : this(execute, null)
{
}
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
if (_canExecute.Equals(null))
{
return true;
}
return _canExecute(parameter);
}
public void Execute(object parameter)
{
_execute(parameter);
}
public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, EventArgs.Empty);
}
}
}
}
Here is the property and the function that I am trying to pass:
using QMAC.Models;
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Text;
using System.Windows.Input;
using System.Windows.Threading;
namespace QMAC.ViewModels
{
class MainViewModel: ViewModelBase
{
Address address;
Location location;
private string _locationPicked;
private string _ipAddress;
private DelegateCommand _exportCommand;
public MainViewModel()
{
address = new Address();
location = new Location();
_ipAddress = address.IPAddress;
_exportCommand = new DelegateCommand(ExportCommand);
}
public ICommand ExportCommand
{
get { return _exportCommand; }
}
public void ExportList()
{
}
}
}
Because the 1st error has to deal with an overloaded method I know I'm just overlooking something really simple. As for the second error, what would be a better way to handle that since I can't pass that Property.