DelegateCommand 클래스가 있고 그 안에 2 개의 생성자가 있습니다. 내가 그 클래스의 생성자에 내 재산을 통과 할 때 나는라는 오류 메시지가 얻을 : 내 DelegateCommand를 들어DelegateCommand에 대한 오버로드 된 메소드
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>'
을, 여기에 내가 (코멘트 짧은 그것을 유지하지 않고) 무엇을 가지고 :
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);
}
}
}
}
여기에 호텔과 내가 통과하려고하는 기능입니다 : 1 오류가 난 그냥 정말 간단 뭔가를 내려다 해요 알고 오버로드 된 방법으로 처리해야하기 때문에
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()
{
}
}
}
은. 두 번째 오류에 관해서는, 내가 그 Property를 통과 할 수 없기 때문에 그것을 처리하는 더 좋은 방법은 무엇이겠습니까.
생성자는'Action
그럼 어떻게해야합니까? – tylerbhughes