using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApplication1
{
/// <summary>
/// Window9.xaml 的交互逻辑
/// </summary>
public partial class Window9 : Window
{
public Window9()
{
InitializeComponent();
this.DataContext = new ViewModel();
}
}
class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

public void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
class DelegateCommand : ICommand
{
//A method prototype without return value.
public Action<object> ExecuteCommand = null;
//A method prototype return a bool type.
public Func<object, bool> CanExecuteCommand = null;
public event EventHandler CanExecuteChanged;

public bool CanExecute(object parameter)
{
if (CanExecuteCommand != null)
{
return this.CanExecuteCommand(parameter);
}
else
{
return true;
}
}

public void Execute(object parameter)
{
if (this.ExecuteCommand != null) this.ExecuteCommand(parameter);
}

public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, EventArgs.Empty);
}
}
}
class Model : NotificationObject
{
private string _wpf = "WPF";

public string WPF
{
get { return _wpf; }
set
{
_wpf = value;
this.RaisePropertyChanged("WPF");
}
}

public void Copy(object obj)
{
this.WPF += " WPF";
}

}
class ViewModel
{
public DelegateCommand CopyCmd { get; set; }
public Model model { get; set; }

public ViewModel()
{
this.model = new Model();
this.CopyCmd = new DelegateCommand();
this.CopyCmd.ExecuteCommand = new Action<object>(this.model.Copy);
}
}

}

________________________________

<Window x:Class="WpfApplication1.Window9"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window9" Height="300" Width="300">
<Grid>
<StackPanel VerticalAlignment="Top">
<TextBlock Text="{Binding model.WPF}" Height="208" TextWrapping="WrapWithOverflow"></TextBlock>
<Button Command="{Binding CopyCmd}" Height="93" Width="232" Content="Copy" Margin="30,0"/>
</StackPanel>
</Grid>
</Window>

wpf中INotifyPropertyChanged的用法的更多相关文章

  1. WPF中StringFormat的用法

    原文:WPF中StringFormat的用法 WPF中StringFormat的用法可以参照C#中string.Format的用法 1. C#中用法: 格式化货币(跟系统的环境有关,中文系统默认格式化 ...

  2. WPF中StringFormat的用法--显示特定位数的数字

    原文:WPF中StringFormat的用法--显示特定位数的数字 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/art ...

  3. 整理:WPF中XmlDataProvider的用法总结

    原文:整理:WPF中XmlDataProvider的用法总结 一.目的:了解XmlDataProvider中绑定数据的方法 二.绑定方式主要有三种: 1.Xaml资源中内置: <!--XPath ...

  4. 整理:WPF中CommandBindings的用法

    原文:整理:WPF中CommandBindings的用法 目的:了解一下CommandBindings.InputBindings.ICommandSource中在WPF中扮演什么样的角色 Comma ...

  5. WPF中INotifyPropertyChanged用法与数据绑定

    在WPF中进行数据绑定的时候常常会用到INotifyPropertyChanged接口来进行实现,下面来看一个INotifyPropertyChanged的案例. 下面定义一个Person类: usi ...

  6. WPF中log4net的用法

    WPF中如何使用log4nethttp://www.cnblogs.com/C-Sharp2/archive/2013/04/12/WPF-LOG4NET.html Apache log4net Ma ...

  7. 在 WPF 中的线程

    线程处理使程序能够执行并发处理,以便它可以做多个操作一次.节省开发人员从线程处理困难的方式,设计了 WPF (窗口演示文稿基金会).这篇文章可以帮助理解线程在 WPF 中的正确用法. WPF 内部线程 ...

  8. WPF中StringFormat 格式化 的用法

    原文 WPF中StringFormat 格式化 的用法 网格用法 <my:DataGridTextColumn x:Name="PerformedDate" Header=& ...

  9. WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选)

    原文:WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选) 前台代码 <DataGrid.Columns> <DataGridCheckB ...

随机推荐

  1. Java基础00-方法引用32

    1. 方法引用 Java8新特征之方法引用 1.1 体验方法引用 代码示例: 需求: 1:定义一个接口(Printable):里面定义一个抽象方法: void printString(String s ...

  2. Scanner的基本语法及用法

    一.Scanner对象 基本语法中并没有实现程序和人的交互,但是Java给我们提供了一个这样的工具类,我们可以获取用户的输入.java.util.Scanner是Java5的新特征,我们可以通过Sca ...

  3. linux服务器环境部署(三、docker部署nginx)

    一.下载nginx镜像 官网地址:https://hub.docker.com/_/nginx #下载镜像 默认为最新版本 docker pull nginx#下载指定版本 docker pull n ...

  4. list实现从大到小排序

    public static void main(String[] args) { List<Integer> list=new ArrayList<Integer>(); // ...

  5. Jenkins远程命令执行漏洞(CVE-2018-1000861)

    此漏洞没有回显,直接利用orange的exp执行命令反弹shell 工具地址https://github.com/orangetw/awesome-jenkins-rce-2019 web服务器下写1 ...

  6. SpringCloud升级之路2020.0.x版-5.所有项目的parent与spring-framework-common说明

    本系列代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford 源代码文件:htt ...

  7. jmeter永久调为中文

    将jmeter调为中文有两种方法,一是在软件设置中切换,二是修改配置文件. 第一种方式是临时的,下次重新打开会变回为英文 第二种方式是永久的,每次打开都会显示自己配置好的语言 第一种方式: 第二种方式 ...

  8. Android全新UI编程 - Jetpack Compose 超详细教程

    1. 简介 Jetpack Compose是在2019Google i/O大会上发布的新的库.Compose库是用响应式编程的方式对View进行构建,可以用更少更直观的代码,更强大的功能,能提高开发速 ...

  9. Spring Cloud Alibaba - SkyWalking

    SkyWalking 简介 分布式链路跟踪是分布式系统的应用程序性能监视工具,专为微服务.云原生架构和基于容器(Docker.K8s)架构而设计: 也就是说Skywalking是用于微服务的" ...

  10. Python语言系列-05-模块和包

    自定义模块 #!/usr/bin/env python3 # author:Alnk(李成果) # 为什么要有模块?(内置函数不够用) # 和操作系统打交道 # 和python解释器打交道 # 和时间 ...