通知项熟悉、数据绑定

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. learning docker steps(7) ----- docker registry 搭建

    参考: https://docs.docker.com/engine/reference/builder/ https://hub.docker.com/_/registry/ https://www ...

  2. Delphi中的文件扩展名

    Filename Extensions in Delphi http://delphi.about.com/od/beginners/a/aa032800a.htm Try building a sm ...

  3. C语言atoi函数(将字符串转化为int)

    头文件:#include <stdlib.h> atoi() 函数用来将字符串转换成整数(int),其原型为:int atoi (const char * str); [函数说明]atoi ...

  4. git在idea中的使用,如何构远程git方仓库

    git 下载:http://learning.happymmall.com/git/   配置用户名:$ git config --glob user.name "forever" ...

  5. 玩转X-CTR100 l STM32F4 l X-CTR100与树莓派搭建机器人平台

    我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ] 本文介绍X-CTR100控制器与树莓派Linux系统 ...

  6. Ad Muncher 目前半价优惠^_^

    优惠地址

  7. 卡巴斯基KAV2013 – 免费一年 (六一活动)

    赠送时间:2013年5月31日10时 至 2013年6月1日24时赠送产品:卡巴斯基反病毒软件2013(一年版)赠送方式:产品激活码将以电邮方式发送到您提交信息的邮箱里,每个邮箱仅能领取一个激活码.温 ...

  8. IOS控件大全及控件大小

    一 视图UIView和UIWindow iphone视图的规则是:一个窗口,多个视图.UIWindow相当于电视机,UIViews相当于演员. 1.显示数据的视图 下面几个类可在屏幕上显示信息: UI ...

  9. 解压Ubuntu的initrd.img的方法

    Ubuntu的initrd.img可以在/boot中找到,通常文件名后面还跟有很长的一串版本号. 为了保险起见,不直接操作原文件,而是把它复制到自己的家目(home)录中.如果你是用root帐号登录的 ...

  10. VC++ 6.0 C8051F340 USB PC侧通信 Demo

    // HelloWorld.cpp : Defines the entry point for the console application. // /*********************** ...