المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Converting from VB.NET



C# Programming
11-18-2012, 01:30 PM
In VB.NET I do this:

Public Property LogoutCommand As ICommand...LogoutCommand = New RelayCommand(AddressOf LogoutExecute, AddressOf CanLogoutExecute)
but when I try this in C#:
public ICommand LogoutCommand;...LogoutCommand = new RelayCommand(LogoutExecute, CanLogoutExecute);...private void LogoutExecute(){...}private bool CanLogoutExecute(){ return true;}...I get an error: "the best overloaded method match for RelayCommand(System.Action, System.Predicate) has some invalid arguments"

Here is the RelayCommand Class:
public class RelayCommand : ICommand { private readonly Action _execute; private readonly Predicate _canExecute; public RelayCommand(Action execute): this(execute, null){ } public RelayCommand(Action execute, Predicate canExecute) { if (execute == null) { throw new ArgumentException("execute"); } _execute = 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); } } public class RelayCommand : ICommand { private readonly Action _execute; private readonly Predicate _canExecute; public RelayCommand(Action execute): this(execute, null){} public RelayCommand(Action execute, Predicate canExecute) { if (execute == null) { throw new ArgumentException("execute"); } } [DebuggerStepThrough()] public bool CanExecute(object parameter) { return _canExecute == null ? true : _canExecute((T)parameter); } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public void Execute(object parameter) { _execute((T) parameter); } }
Any suggestions?
I don't speak Idiot - please talk slowly and clearly

"I have sexdaily. I mean dyslexia. Fcuk!"

Driven to the arms of Heineken by the wife