通知项熟悉、数据绑定

using System.ComponentModel;

namespace Demo6
{
/// <summary>
/// 通知项属性
/// </summary>
public class Student : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string name; public string Name
{
get { return name; }
set
{
name = value;
if (this.PropertyChanged != null)
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Name"));
}
}
}
}
} using System.ComponentModel; namespace Demo6
{
public class MainWindowModele : INotifyPropertyChanged
{
private string _name = "张三";
public string Name
{
get { return _name; }
set
{
_name = value;
OnPropertyChanged("Name");
}
} public MainWindowModele()
{
} public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}

  

<Window x:Class="Demo6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<!--绑定是一种自动机制-->
<TextBox x:Name="txtTest" Text="{Binding Name,Mode=TwoWay}" Margin="5"/>
<Button x:Name="btnTest" Margin="10" Width="75" Height="50" Content="add age" Click="btnTest_Click"/>
<TextBox x:Name="txtTest2" Text="{Binding ElementName=txtTest,Path=Text, Mode=TwoWay}" Margin="5"/>
<TextBox x:Name="txtTest3" Text="{Binding ElementName=txtTest2,Path=Text, Mode=TwoWay}" Margin="5"/>
</StackPanel>
</Window>
using System.Windows;

namespace Demo6
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private Student stu = new Student(); public MainWindow()
{
InitializeComponent(); MainWindowModele mwm = new MainWindowModele();
this.DataContext = mwm; //方式一
//Binding b = new Binding();
//b.Source = stu;
//b.Path = new PropertyPath("Name");
//BindingOperations.SetBinding(this.txtTest,TextBox.TextProperty,b); //方式二
// this.txtTest.SetBinding(TextB.Te//xtProperty, new Binding("Name") { Source = stu = new Student() });
} private void btnTest_Click(object sender, RoutedEventArgs e)
{
stu.Name += "";
}
}
}

WPF Demo6的更多相关文章

  1. 在WPF中使用依赖注入的方式创建视图

    在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...

  2. MVVM框架从WPF移植到UWP遇到的问题和解决方法

    MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...

  3. MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息

    MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...

  4. MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信

    MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...

  5. MVVM设计模式和WPF中的实现(四)事件绑定

    MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  6. MVVM模式解析和在WPF中的实现(三)命令绑定

    MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  7. MVVM模式和在WPF中的实现(二)数据绑定

    MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  8. MVVM模式和在WPF中的实现(一)MVVM模式简介

    MVVM模式解析和在WPF中的实现(一) MVVM模式简介 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在 ...

  9. 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])

    常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...

随机推荐

  1. 猎豹浏览器(chrome内核)屏蔽视频广告

    1.基于猎豹浏览器(原则上chrome内核浏览器都可以) 2.下载插件Adblock Plus,下载地址:http://chromecj.com/productivity/2014-07/24/dow ...

  2. Beand的高级特征

    Spring程序中,Java Bean一般与Spring是非耦合的,不会依赖于Spring类库.这也是Spring的优点. 实现BeanNameAware接口获取本bean的id属性 BeanName ...

  3. Free 4 months Serial License Key Of Outpost Security Suite Pro 8.1

    VISIT HEREto gey a 1 year key.... for the latest version Promo code ? well use the same here too : C ...

  4. SharePoint 2010 Ribbon with wrong style in Chrome and Safari

    When we add custom ribbon to SharePoint 2010, it may display well in IE but not in Chrome and Safari ...

  5. docker中的安全机制

    有时候我们需要容器具有更多的权限,像如操作内核模块,控制swap交换分区,挂载usb磁盘,修改mac地址等.所以我们今天进行docker的安全设定. 一.使用docker命令设置docker的安全机制 ...

  6. Ubuntu 搭建Ghost1.0博客系统

    最近想使用Ghost搭建自己的博客网站,网上搜索了下大多都是1.0之前版本搭建的文章,但是Ghost1.0版本已经可用好一段时间了,所以决定根据官方文档搭建Ghost1.0版本的博客系统. 下面开始一 ...

  7. uDig配图与GeoServer添加Style

    软件介绍: uDig是一个开源的桌面GIS软件,可以进行shp与栅格数据地图文件的编辑和查看,对OpenGIS标准,关于互联网GIS.网络地图服务器和网络功能服务器有特别的加强.通常和GeoServe ...

  8. 50个必备常用的jQuery代码段

    1. 如何修改jQuery默认编码(例如默认UTF-8改成改GB2312): $.ajaxSetup({ ajaxSettings:{ contentType:"application/x- ...

  9. HDU 4970

    http://acm.hdu.edu.cn/showproblem.php?pid=4970 比赛的时候线段树水过的,比赛后线段树一直T,看了下正解真的是智商压制 题意:走直线,长度1-N,还有一些人 ...

  10. shell 脚本实战笔记(11)--Mysql在linux下的安装和简单运维

    前言: linux中安装mysql以及配置的管理, 基础的运维和管理还是需要会一些的. 这边作下笔记, 以求天天向上(^_^). 安装流程:*). 安装mysql-server1). 借助yum检索相 ...