WPF Demo6
通知项熟悉、数据绑定
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的更多相关文章
- 在WPF中使用依赖注入的方式创建视图
在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...
- MVVM框架从WPF移植到UWP遇到的问题和解决方法
MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...
- MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息
MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...
- MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信
MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...
- MVVM设计模式和WPF中的实现(四)事件绑定
MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式解析和在WPF中的实现(三)命令绑定
MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式和在WPF中的实现(二)数据绑定
MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式和在WPF中的实现(一)MVVM模式简介
MVVM模式解析和在WPF中的实现(一) MVVM模式简介 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在 ...
- 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])
常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...
随机推荐
- vs2015 企业版、专业版如何破解(秘钥)
安装完vs2015 企业版后,在菜单帮助---注册产品,显示产品试用期30天,怎么破解呢? 一.破解秘钥 企业版 HM6NR-QXX7C-DFW2Y-8B82K-WTYJV 专业版 HMG ...
- VPNl连接
2服务器IP端口及密码在QQ邮箱 OS Reload on localhost.localdomain [95.169.18.222] SSH port: 29657 69.194.13.216 ...
- Apache自带性能测试工具ab的使用
Apache服务器套件自带ab,只要安装Apache即可,无需另行安装ab.ab位于%ApacheHome%/bin目录下(“%ApacheHome%”为Aapche安装路径),你也可以把ab.exe ...
- ACdream 1067:Triangles
Problem Description 已知一个圆的圆周被N个点分成了N段等长圆弧,求任意取三个点,组成锐角三角形的个数. Input 多组数据,每组数据一个N(N <= 1000000) Ou ...
- 【设计模式】 模式PK:工厂模式VS建造者模式
1.概述 工厂方法模式注重的是整体对象的创建方法,而建造者模式注重的是部件构建的过程,旨在通过一步一步地精确构造创建出一个复杂的对象.我们举个简单例子来说明两者的差异,如要制造一个超人,如果使用工厂方 ...
- PyQt5编程:鼠标事件
参考链接:https://www.cnblogs.com/zhuluqing/p/9028816.html 一.每个事件都被封装成相应的类: pyqt中,每个事件类型都被封装成相应的事件类,如鼠标事件 ...
- SWIFT中使用AFNetwroking访问网络数据
AFNetworking 是 iOS 一个使用很方便的第三方网络开发框架,它可以很轻松的从一个URL地址内获取JSON数据. 在使用它时我用到包管理器Cocoapods 不懂的请移步: Cocoapo ...
- Python+Requests接口测试教程(2):requests
开讲前,告诉大家requests有他自己的官方文档:http://cn.python-requests.org/zh_CN/latest/ 2.1 发get请求 前言requests模块,也就是老污龟 ...
- [LeetCode&Python] Problem 136. Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single on ...
- HDU 1024:Max Sum Plus Plus(DP,最大m子段和)
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...