Con risposta WPF TextBox Trigger Text changed Event

Tutte le risposte

  • mercoledì 7 marzo 2012 13:41
     
     
    Do you mean to have access to it in your viewmodel?
  • mercoledì 7 marzo 2012 14:40
    Moderatore
     
     Risposta suggerita Contiene codice

    If you are referring to the "Relay Command", it's not Galasoft's IP anyway, they've just made a very nice implementation.

    Before I started using MVVMLite I had my own library of such things, as you will find it scattered all over the Internet.

    One of the most well known versions/sources for the code of a Relay Command is MSDN Magazine.

        

    public class RelayCommand : ICommand
    {
        #region Fields
    
        readonly Action<object> _execute;
        readonly Predicate<object> _canExecute;        
    
        #endregion // Fields
    
        #region Constructors
    
        public RelayCommand(Action<object> execute)
        : this(execute, null)
        {
        }
    
        public RelayCommand(Action<object> execute, Predicate<object> canExecute)
        {
            if (execute == null)
                throw new ArgumentNullException("execute");
    
            _execute = execute;
            _canExecute = canExecute;           
        }
        #endregion // Constructors
    
        #region ICommand Members
    
        [DebuggerStepThrough]
        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }
    
        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    
        public void Execute(object parameter)
        {
            _execute(parameter);
        }
    
        #endregion // ICommand Members
    }

         

    Regards,
    Pete


    #PEJL


  • giovedì 8 marzo 2012 06:23
    Moderatore
     
     Con risposta

    Hi Parsita,

    I think you could refer to AttachedCommandBehavior, there is an AttachedCommandBehavior(ACB) library,

    http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/

    This feature will help you hook command to any event, and it has provided a complete sample you could refer to.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.