Click here to Skip to main content
11,637,002 members (68,715 online)
   

C#

 
QuestionConverting from VB.NET Pin
Andy_L_J17-Nov-12 21:39
memberAndy_L_J17-Nov-12 21:39 
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<object>, System.Predicate<object>) has some invalid arguments"

Here is the RelayCommand Class:
public class RelayCommand : ICommand
	{
		private readonly Action<Object> _execute;
		private readonly Predicate<Object> _canExecute;
 
		public RelayCommand(Action<object> execute): this(execute, null){	}
 
		public RelayCommand(Action<object> execute, Predicate<Object> 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<T> : ICommand
	{
		private readonly Action<T> _execute;
		private readonly Predicate<T> _canExecute;
 
		public RelayCommand(Action<T> execute): this(execute, null){}
 
		public RelayCommand(Action<T> execute, Predicate<T> 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


modified 18-Nov-12 3:54am.

AnswerRe: Converting from VB.NET Pin
DaveyM6917-Nov-12 22:23
mentorDaveyM6917-Nov-12 22:23 
GeneralRe: Converting from VB.NET Pin
Andy_L_J17-Nov-12 22:54
memberAndy_L_J17-Nov-12 22:54 
GeneralRe: Converting from VB.NET Pin
DaveyM6918-Nov-12 7:10
mentorDaveyM6918-Nov-12 7:10 
GeneralRe: Converting from VB.NET Pin
Andy_L_J18-Nov-12 11:12
memberAndy_L_J18-Nov-12 11:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 30 Jul 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid