Note - Tips - Trick - .Net

Lưu các thủ thuật, code mẫu, cách dùng về .Net

RelayCommand binding command WPF RelayCommand binding command WPF RelayCommand binding command WPF RelayCommand binding command WPF RelayCommand binding command WPF 1/5 (13 reviews)

RelayCommand binding command WPF

Đã đăng 2017-12-23 05:35:23 bởi K9
0 bình luận 1681 lượt xem
RelayCommand binding command WPF 1 /5 stars (1 reviews)
 

ReplayCommand.cs

 

 class RelayCommand<T> : ICommand
    {
        private readonly Predicate<T> _canExecute;
        private readonly Action<T> _execute;

        public RelayCommand(Predicate<T> canExecute, Action<T> execute)
        {
            if (execute == null)
                throw new ArgumentNullException("execute");
            _canExecute = canExecute;
            _execute = execute;
        }

        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute((T)parameter);
        }

        public void Execute(object parameter)
        {
            _execute((T)parameter);
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    }

 

Chia sẻ:
Thảo luận Hỏi và đáp Báo lỗi bài viết
Hủy bỏ   hoặc  
Hủy bỏ   hoặc  
Hủy bỏ   hoặc  

Chiến dịch

Kteam - Howkteam Free Education