I want to capture mouse clicks on a TextBox
:
Here's code example for those who are using MVVM
It works fine for events that are inheriting from Control.
In ViewModel:
private ICommand _merchantRefereneceCommand;
public ICommand MerchantReferenceCopyToClipboard
{
get { return _merchantRefereneceCommand ?? (_merchantRefereneceCommand = new MerchantRefereneceCommand(this)); }
set { _merchantRefereneceCommand = value; }
}
public class MerchantRefereneceCommand : ICommand
{
private readonly PaymentViewModel _paymentViewModel;
public MerchantRefereneceCommand(PaymentViewModel paymentViewModel)
{
_paymentViewModel = paymentViewModel;
}
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
//Your code goes here.
}
public event EventHandler CanExecuteChanged;
}
In View (xaml):
Hope this saves you some time.