WPF customize DelegateCommand

Posted fred1987

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF customize DelegateCommand相关的知识,希望对你有一定的参考价值。

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!");
        }
    }
}

 

以上是关于WPF customize DelegateCommand的主要内容,如果未能解决你的问题,请参考以下文章

WPF中的Generic.xaml, theme以及custom control

winform AutoCompleteCustomSource.AddRange

WPF使用IDataErrorInfo进行数据校验

INotifyPropertyChanged WPF

wpf datagrid observablecollection

自定义滚动条(Custom ScrollBar)