<!--MainWindow.xaml-->
<Window x:Class="UserStore.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" Loaded="Window_Loaded">
<Grid>
<!--数据绑定 Text-->
<TextBox Height="23" Text="{Binding Name}" HorizontalAlignment="Left" Margin="50,22,0,0" Name="txtName" VerticalAlignment="Top" Width="155" />
<TextBox Height="23" Text="{Binding Age}" HorizontalAlignment="Left" Margin="50,70,0,0" Name="txtAge" VerticalAlignment="Top" Width="155" />
<Button Content="年龄自增" Height="23" HorizontalAlignment="Left" Margin="50,164,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</Window>
//MainWindow.xaml.cs
using System;
using System.Collections.Generic;
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.Navigation;
using System.Windows.Shapes; namespace UserStore
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private Person p1 = new Person(); public MainWindow()
{
InitializeComponent();
} private void Window_Loaded(object sender, RoutedEventArgs e)
{
p1.Name = "Lee";
p1.Age = 26; txtName.DataContext = p1;
txtAge.DataContext = p1;
} private void button1_Click(object sender, RoutedEventArgs e)
{
p1.Age++;
}
}
}
//Person.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel; namespace UserStore
{
//class Person
//{
// public int Age
// {
// get;
// set;
// }
// public string Name
// {
// get;
// set;
// }
//} //内置的类,会监测INotifyPropertyChanged是否实现了,得知属性变化
class Person : INotifyPropertyChanged
{
private int age; public int Age
{
get { return age; }
set
{
this.age = value;
if (PropertyChanged != null)
{
//触发事件
PropertyChanged(this, new PropertyChangedEventArgs("Age"));
}
}
}
public string Name
{
get;
set;
} public event PropertyChangedEventHandler PropertyChanged;
}
}

C#_wpf_userinput_数据绑定_后台对象改变,界面数据也变化的更多相关文章

  1. 【JSON 注解】JSON循环引用2----JSON注解@JsonIgnoreProperties+JAVA关键字transient+后台对象与JSON数据的格式互相转化

    接着来说这个JSON循环引用的问题: 关于JSON格式的转化,其实关键就是这几个依赖: <!-- json --> <!-- 1号 --> <dependency> ...

  2. matlab学习笔记9 高级绘图命令_1 图形对象_根对象,轴对象,用户控制对象,用户菜单对象

    一起来学matlab-matlab学习笔记9 高级绘图命令_1 图形对象_根对象,轴对象,用户控制对象,用户菜单对象 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matl ...

  3. Ajax编程中,经常要能动态的改变界面元素的样式

    在Ajax编程中,经常要能动态的改变界面元素的样式,可以通过对象的style属性来改变,比如要改变背景色为红色,可以这样写:element.style.backgroundColor=”#ff0000 ...

  4. react_app 项目开发 (5)_前后端分离_后台管理系统_开始

    项目描述 技术选型 react API 接口 接口文档,url,请求方式,参数类型, 根据文档描述的方法,进行 postman 测试,看是否能够得到理想的结果 collections - 创建文件取项 ...

  5. from表单提交数据之后,后台对象接受不到值

    如果SSH框架下,前段页面通过from表单提交数据之后,在后台对象显示空值,也就是接收不到值得情况下.首先保证前段输入框有值,这个可以在提交的时候用jQuery的id或者name选择器alert弹出测 ...

  6. Django配置后台xadmin管理界面

    Django配置后台xadmin管理界面 python版本3.6.5 Django版本1.10.8(刚开始是2.1.5,由于各种错误,改成了低版本) 1.xadmin的安装,下载地址https://g ...

  7. c# 把对象加入队列,对象为全局变量,对象改变队列值也跟着改变

    若程序把对象加入队列,对象为全局变量,对象改变队列值也跟着改变,如下: filecontent  为两个字段的属性值. class FileContent { // public string Htt ...

  8. Flutter实战视频-移动电商-30.列表页_商品列表UI界面布局

    30.列表页_商品列表UI界面布局 小程序里面的布局方式 小程序的图片上这里使用的是warp布局,因为首页里面火爆专区,已经用过了warp来布局了. 所以这里我们没有必要再讲一遍,这里我们使用List ...

  9. cb25a_c++_函数对象简介

    cb25a_c++_函数对象简介预定义的函数对象https://blog.csdn.net/txwtech/article/details/104382505negate<type>()p ...

随机推荐

  1. 交易的成功 = 60%的资金管理 + 40%出入场信号 zt

    交易的成功 = 60%的资金管理 + 40%出入场信号. 资金管理   = 60%的风险分散 + 40%的适度重或轻仓. 出入场信号 = 60%的出场信号 + 40%的入场信号. 交易的成功 = 36 ...

  2. Python脚本控制的WebDriver 常用操作 <二十四> 定位frame中的元素

    测试用例场景 处理frame需要用到2个方法,分别是switch_to_frame(name_or_id_or_frame_element)和switch_to_default_content() 如 ...

  3. ubuntu网站做图像外链

    http://paste.ubuntu.org.cn

  4. 解决js获取数据跨域问题,jsonP

    网上说了一些jsonp的示例,感觉都没用,最后研究了一下,调用腾讯的一个api.最后要加output=jsonp&callback=?这个,比较适用. var url = "http ...

  5. bzoj 2815 [ZJOI2012]灾难(构造,树形DP)

    [题意] 求把每个点删除后,不可达点的数目. [思路] 构造一棵“灭绝树”,要求这棵树满足如果删除根节点后则该子树内的所有结点都不可达.则答案为子树大小-1. 如何构造这棵“灭绝树”? 将原图拓扑排序 ...

  6. NOIP 2014 无线网络发射器选址

    水题..直接暴力 #include<cstdio> #include<algorithm> using namespace std; const int inf = 0x3f3 ...

  7. HW6.6

    public class Solution { public static void main(String[] args) { int[] prime = new int[50]; prime[0] ...

  8. HDU-4619 Warm up 2 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 一看就知道是二分匹配题目,对每个点拆点建立二分图,最后答案除2.因为这里是稀疏图,用邻接表处理. ...

  9. Install PhoneGap

    To Install, ensure that you have NodeJS installed, then open your commandline and run the following: ...

  10. 转载 基于Selenium WebDriver的Web应用自动化测试

    转载原地址:  https://www.ibm.com/developerworks/cn/web/1306_chenlei_webdriver/ 对于 Web 应用,软件测试人员在日常的测试工作中, ...