WPF Commands, How to declare Application level commands?

后端 未结 5 685
不思量自难忘°
不思量自难忘° 2020-12-09 03:41

I\'m interested in creating commands that are available from anywhere in my WPF application.

I\'d like them to work in the same way as Cut, Copy

5条回答
  •  不知归路
    2020-12-09 04:29

    Declare the CommandBinding at Application level from where it can be re-used everywhere.

           
        
    
    

    In your App.xaml.cs file, define corresponding handlers :

      private void CommandBinding_CanExecute_11(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        {
          e.CanExecute = false;
        }
    

    Usage

    In any xaml file, use it like below :

                 
            
                
            
    

提交回复
热议问题