WPF customize DelegateCommand

跟風遠走 提交于 2019-12-05 11:45:29
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace WpfApp55.ViewModel
{
    public class VM : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propName));
            }
        }

        private DelegateCommand UCCmdValue;
        public DelegateCommand UCCmd
        {
            get
            {
                if(UCCmdValue==null)
                {
                    UCCmdValue = new DelegateCommand(UCCmdExecuted, UCCmdCanExecute);
                }
                return UCCmdValue;
            }
        }

        private bool UCCmdCanExecute(object obj)
        {
            return true;
        }

        private void UCCmdExecuted(object obj)
        {
            MessageBox.Show("You had clicked the customized button!");
        }
    }
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!