RelayCommand's reference is not found
RelayCommand is a class created by MS for handling event or command in WPF. you can create own class or go through below link.
This does not necessarily have to be RelayCommand
it's simply a name of class from most common example on the web.
The mechanism of ICommand
works in a way that instead of getter or setter being called you get public void Execute(object parameter)
to be called on class that is implementing ICommand
Let me give you an example:
I have a hyperlink which when clicked should do some stuff before redirecting person to browser.
XAML
<Hyperlink NavigateUri="https://payments.epdq.co.uk/ncol/prod/backoffice/" Command="{Binding Path=NavigateToTakePayment}" IsEnabled="{Binding CanTakePayment}"> Launch Payments Portal</Hyperlink>
now in viewModel I have property
public ICommand NavigateToTakePayment { get { return _navigateToTakePayment ?? (_navigateToTakePayment = new NavigateToTakePaymentCommand(this)); } set { _navigateToTakePayment = value; }}
but when hyperlink is clicked instead of getter being fired like one would expect NavigateToTakePaymentCommand
class Execute
method is fired instead.
public class NavigateToTakePaymentCommand : ICommand { public NavigateToTakePaymentCommand(PaymentViewModel paymentViewModel) { ViewModel = paymentViewModel; } public PaymentViewModel ViewModel { get; set; } public bool CanExecute(object parameter) { return true; } public void Execute(object parameter) { //your implementation stuff goes here. } public event EventHandler CanExecuteChanged; }
I hope this example will clarify how the mechanism works and will save you some time.