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!");
}
}
}
  public class DelegateCommand : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute; public event EventHandler CanExecuteChanged; public DelegateCommand(Action<object> execute)
: this(execute, null)
{
} public DelegateCommand(Action<object> execute,
Predicate<object> canExecute)
{
_execute = execute;
_canExecute = canExecute;
} public bool CanExecute(object parameter)
{
if (_canExecute == null)
{
return true;
} return _canExecute(parameter);
} public void Execute(object parameter)
{
_execute(parameter);
} public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, EventArgs.Empty);
}
}
}

WPF customize DelegateCommand的更多相关文章

  1. WPF Customize TabControl

    有篇很好的文章 http://www.blogs.intuidev.com/post/2010/01/25/TabControlStyling_PartOne.aspx 详细介绍了如何Customiz ...

  2. 使用MVVM设计模式构建WPF应用程序

    使用MVVM设计模式构建WPF应用程序 本文是翻译大牛Josh Smith的文章,WPF Apps With The Model-View-ViewModel Design Pattern,译者水平有 ...

  3. WPF系列 Style

        参考 WPF: Customize your Application with Styles and Control Templates (Part 2 of 2)

  4. WPF - 为什么不能往Library的工程中添加WPF window

    项目中添加一个Library 工程,但是却无法加入WPF window, WPF customize control. 调查了一下,发现这一切都由于Library工程中没有:ProjectTypeGu ...

  5. 什么是MVVM模式

    问题引入1 场景一:团队辛辛苦苦完成了一个项目,抱着激动的心情去给用户做demo,而用户给你的反馈是UI很不满意,要重新修改,否则拒绝验收.大规模修改UI,晴天霹雳!2 场景二:产品在一家客户上线运行 ...

  6. 2018-2-13-WPF-DelegateCommand-出现Specified-cast-is-not-valid

    title author date CreateTime categories WPF DelegateCommand 出现Specified cast is not valid lindexi 20 ...

  7. WPF之MVVM(Step2)——自己实现DelegateCommand:ICommand

    在自己实现MVVM时,上一篇的实现方式基本是不用,因其对于命令的处理不够方便,没写一个命令都需要另加一个Command的类.此篇主要介绍DelegateCommand来解决上面所遇到的问题. 首先,我 ...

  8. WPF DelegateCommand 出现Specified cast is not valid

    使用 DelegateCommand 出现 Specified cast is not valid 最近写快捷键需要 DelegateCommand ,于是用了 DelegateCommand< ...

  9. WPF委托命令DelegateCommand的传参方式

    首先引用  Microsoft.Practices.Prism MVVM模式代码如下: XAML代码: <!-- 无参方式 --> <Button Content="Tes ...

随机推荐

  1. dev gridcontrol绘制页脚

    gridView.OptionsView.ShowFooter = true;//启用显示页脚 //索引为1的列 gridView.Columns[1].SummaryItem.DisplayForm ...

  2. 微服务架构 SpringBoot(一)

    spring Boot:官网地址 https://spring.io/ 由来: 随着spring组件功能的强大,配置文件也越来越复杂繁琐,背离了spring公司的简洁快速开发原理,2015年就推出Sp ...

  3. [ASP.NET Core 3框架揭秘] 文件系统[4]:程序集内嵌文件系统

    一个物理文件可以直接作为资源内嵌到编译生成的程序集中.借助于EmbeddedFileProvider,我们可以采用统一的编程方式来读取内嵌的资源文件,该类型定义在 "Microsoft.Ex ...

  4. python 多线程编程之进程和线程基础概念

    多线程编程 在多线程(multithreaded,MT)出现之前,计算机程序的执行都是由单个步骤序列组成的,该序列组合在主机的CPU中按照同步顺序执行.无论是任务本身需要按照步骤顺序执行,还是整个过程 ...

  5. IDEA中使用Maven模板创建Maven WebApp项目并使用Tomact来运行项目

    首先需要正确安装Maven和Tomact,Maven安装和Tomact安装步骤,参见别的文章. 一.创建Maven工作空间 点击Finish按钮后,耐心等待.直到出现BUILD SUCCESS为止. ...

  6. Castle DynamicProxy基本用法(AOP)

    本文介绍AOP编程的基本概念.Castle DynamicProxy(DP)的基本用法,使用第三方扩展实现对异步(async)的支持,结合Autofac演示如何实现AOP编程. AOP 百科中关于AO ...

  7. 基于Jenkins的开发测试全流程持续集成实践

    今年一直在公司实践CI,本文将近半年来的一些实践总结一下,可能不太完善或优美,但的确初步解决了我目前所在项目组的一些痛点.当然这仅是一家之言也不够完整,后续还会深入实践和引入Kubernetes进行容 ...

  8. javascript学习总结之函数

    前言 在学习javascript函数的时候,有几个经常很容易混淆的方法,call,apply,bind,caller,callee,这些方法的使用,这些也可以说是会频繁使用的一些方法,在此通过查阅相关 ...

  9. python高阶函数——sorted排序算法

    python 内置的sorted()函数可以对一个list进行排序: >>> sorted([8,3,8,11,-2]) [-2, 3, 8, 8, 11] 既然说是高阶函数,那么它 ...

  10. 收藏收藏:工作用了很久的自主开发的Sql Server代码生成器,我开源了(.NET Winform)

    大家好,已经一年没见了,我的技术已经有了惊人的进步.于是乎就来为大家分享技术了,今天呢为大家带来的是很早之前开发的老工具分享给大家. 相信大家都使用过代码生成器,用起来顺手的有多少?根据自己的业务配置 ...