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!");
}
}
}
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的更多相关文章
- WPF Customize TabControl
有篇很好的文章 http://www.blogs.intuidev.com/post/2010/01/25/TabControlStyling_PartOne.aspx 详细介绍了如何Customiz ...
- 使用MVVM设计模式构建WPF应用程序
使用MVVM设计模式构建WPF应用程序 本文是翻译大牛Josh Smith的文章,WPF Apps With The Model-View-ViewModel Design Pattern,译者水平有 ...
- WPF系列 Style
参考 WPF: Customize your Application with Styles and Control Templates (Part 2 of 2)
- WPF - 为什么不能往Library的工程中添加WPF window
项目中添加一个Library 工程,但是却无法加入WPF window, WPF customize control. 调查了一下,发现这一切都由于Library工程中没有:ProjectTypeGu ...
- 什么是MVVM模式
问题引入1 场景一:团队辛辛苦苦完成了一个项目,抱着激动的心情去给用户做demo,而用户给你的反馈是UI很不满意,要重新修改,否则拒绝验收.大规模修改UI,晴天霹雳!2 场景二:产品在一家客户上线运行 ...
- 2018-2-13-WPF-DelegateCommand-出现Specified-cast-is-not-valid
title author date CreateTime categories WPF DelegateCommand 出现Specified cast is not valid lindexi 20 ...
- WPF之MVVM(Step2)——自己实现DelegateCommand:ICommand
在自己实现MVVM时,上一篇的实现方式基本是不用,因其对于命令的处理不够方便,没写一个命令都需要另加一个Command的类.此篇主要介绍DelegateCommand来解决上面所遇到的问题. 首先,我 ...
- WPF DelegateCommand 出现Specified cast is not valid
使用 DelegateCommand 出现 Specified cast is not valid 最近写快捷键需要 DelegateCommand ,于是用了 DelegateCommand< ...
- WPF委托命令DelegateCommand的传参方式
首先引用 Microsoft.Practices.Prism MVVM模式代码如下: XAML代码: <!-- 无参方式 --> <Button Content="Tes ...
随机推荐
- 2019 The Preliminary Contest for ICPC China Nanchang National Invitational(A 、H 、I 、K 、M)
A. PERFECT NUMBER PROBLEM 题目链接:https://nanti.jisuanke.com/t/38220 题意: 输出前五个完美数 分析: 签到.直接百度完美数输出即可 #i ...
- 浅析 Java 与 C++ 的垃圾回收机制
Java老师在期末复习大纲上出了一道关于JVM垃圾回收机制的题目,想要我们简述一下JVM垃圾回收机制,与老师交流后,大概老师是希望通过与其他语言在垃圾回收对比,介绍一下Java在这方面的特点和 ...
- JS 获取元素、修改元素/css样式/标签属性、简单事件、数据类型
基本使用 写在Script 标签里 引入外部js文件:<script src=" "></script> console.log(" " ...
- 50道Redis面试题史上最全,以后面试再也不怕问Redis了
1.什么是Redis? Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库统统加载在内存当中进行操作,定期通过异步操作把数据库数据flush到硬盘上进行保存. ...
- 1001 害死人不偿命的(3n+1)猜想 (15 分)
卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在 1950 ...
- 简单了解一下:var 、let、const
var 重新赋值,重新定义,作用域 属于:function scope: let 声明的变量只在 let 命令所在的代码块内有效,Block scope. const 声明一个只读的常量,一旦声明,常 ...
- MySQL的多表联查
1.内连接 规则:返回两个表的公共记录 语法: -- 语法一 select * from 表1 inner join 表2 on 表1.公共字段=表2.公共字段 -- 语法 ...
- Axure制作dialog效果的动作步骤
1.在Axure中添加一个弹框按钮 2.将动态面版拖动到界面中 3.双击动态面版,双击state 4.拖入一块图片占位符进来 5.设置图片 6.回到上一个界面设置动态面版的大小,使其 ...
- QGIS练手 - 数据
又熬夜了... 这篇博客可能会将QGIS数据管理部分和ArcGIS数据管理进行对比学习. 1. 本地数据文件与数据库(矢量) 1.1 文件 QGIS用的是shp文件.kml文件.geojson文件较多 ...
- Dynamics CRM通过定制应用程序功能区为符合条件的实体表单增加按钮
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复167或者20151029可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 前面的博文都是为一个实体添加按钮 ...