Capture mouse clicks on WPF TextBox

前端 未结 3 1011
星月不相逢
星月不相逢 2021-02-03 21:25

I want to capture mouse clicks on a TextBox:



        
3条回答
  •  星月不相逢
    2021-02-03 21:51

    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.

提交回复
热议问题