Prevent double-click from double firing a command

前端 未结 14 1821
情书的邮戳
情书的邮戳 2020-12-15 08:34

Given that you have a control that fires a command:

Is there a way to prevent the command from being fired

14条回答
  •  猫巷女王i
    2020-12-15 09:10

    Wrap the code in a try-catch-finally or try-finally block. The finally statement will always be called regardless of any error occurring in the try.

    Example

        private Cursor _CursorType;
        // Property to set and get the cursor type
        public Cursor CursorType
        {
          get {return _CursorType; }
          set
          {
            _CursorType = value;
            OnPropertyChanged("CursorType");
          }
        }
    
    
        private void ExecutedMethodOnButtonPress()
        {
           try
           {
             CursorType = Cursors.Wait;
             // Run all other code here
           }
           finally
           {
             CursorType = Cursors.Arrow;
           }
        }
    

    NOTE: the CursorType is a property that the UserControl or Window is bound to

    
    

提交回复
热议问题