慈天华 发表于 2024-1-29 18:05:10

通过Demo学WPF—数据绑定(一)✨

前言✨

想学习WPF,但是看视频教程觉得太耗时间,直接看文档又觉得似懂非懂,因此想通过看Demo代码+文档的方式进行学习。
准备✨

微软官方其实提供了WPF的一些Demo,地址为:microsoft/WPF-Samples: <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Repository <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>for <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>WPF <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>related <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>samples <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>(github.com)
将其克隆到本地,有很多的Demo代码:

新建一个空白解决方案:

添加现有项目:

选择Data <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Binding <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>中的 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>SimpleBinding:

项目文件如下所示:

查看SimpleBinding这个Demo的效果:

学习这个Demo✨

数据绑定的概念
首先需要知道数据绑定的基本概念,数据绑定是在应用 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>UI <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>与其显示的数据之间建立连接的过程。 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>如果绑定具有正确的设置,并且数据提供适当的通知,则在数据更改其值时,绑定到该数据的元素会自动反映更改。 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>数据绑定还意味着,如果元素中数据的外部表示形式发生更改,则基础数据可以自动进行更新以反映更改。 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>例如,如果用户编辑 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>TextBox <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>元素中的值,则基础数据值会自动更新以反映该更改。
现在再来看一下,数据绑定的模型图:

现在我们根据这张模型图,学习这个Demo。
这个模型图表示数据绑定至少需要三个东西:

[*]绑定目标
[*]绑定
[*]绑定源
现在我们分别看看这个demo里面,这三个东西在哪?
绑定目标
我们发现这个demo的绑定目标是元素TextBox的Text属性与TextBlock的Text属性。
绑定

这是一个C#类,查找在该Demo中,哪里出现了Binding?
发现在MainWindow.xaml中出现了Binding,有两处地方,分别是:
<TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/><TextBox>
<TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/><TextBox.Text>
<TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/><Binding <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Source="{StaticResource <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>MyDataSource}" <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Path="PersonName"
<TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>UpdateSourceTrigger="PropertyChanged"/>
<TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/></TextBox.Text>
<TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/></TextBox>与
<TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>这两处都是在 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>XAML <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>中声明绑定。
<TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>这种使用的是对象元素语法。
这种使用的是标记扩展。
从这里我们接触到了Binding类的三个属性,Source、Path与UpdateSourceTrigger。
那它们分别是什么意思呢?
先来看下Source:

我们发现这个demo里,Source="{StaticResource <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>MyDataSource},StaticResource <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>MyDataSource又是什么呢?
在Window.Resources标签下有一行代码:

标签在XAML中用于定义可以在整个窗口中重用的资源。这些资源可以是各种类型,包括样式、数据源、数据模板、颜色、画刷等。
这行代码创建了一个Person对象,并将其命名为"MyDataSource",该对象的PersonName属性设置为"Joe",这样你就可以在窗口的其他地方通过这个键来引用这个对象。
因此Source={StaticResource <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>MyDataSource}的意思就是将Binding对象的Source属性设置为键为"MyDataSource"的资源,在这里也就是一个Person对象。
再来看看Path:

表示绑定源属性的路径。
Path="PersonName"表示绑定源是刚刚那个Person对象的PersonName属性。
最后再看看UpdateSourceTrigger:

这个属性可能就会难理解一点。
它表示当绑定目标怎么样时,绑定源的值应该被更新。
它的类型为枚举类型,有以下几个值:
值含义Default绑定目标属性的默认 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>UpdateSourceTrigger <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>值。 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>大多数依赖属性的默认值为 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PropertyChanged,而 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Text <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>属性的默认值为 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>LostFocus。Explicit仅在调用 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>UpdateSource() <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>方法时更新绑定源。LostFocus每当绑定目标元素失去焦点时,都会更新绑定源。PropertyChanged每当绑定目标属性发生更改时,都会更新绑定源。 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Enter <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>a <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Name: <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>我们会发现在这个demo中,TextBox.Text设置了UpdateSourceTrigger属性。
这是因为大多数依赖项属性的默认值为 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PropertyChanged,而 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Text <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>属性的默认值为 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>LostFocus。在这个demo中,我们不希望失去焦点才更新源数据,而是一发生改变就更新绑定源,因此设置UpdateSourceTrigger属性为PropertyChanged。
总结一下,我们遇到的关于Binding类的三个属性Source、Path与UpdateSourceTrigger:
属性名含义Source获取或设置要用作绑定源的对象。Path获取或设置绑定源属性的路径。UpdateSourceTrigger获取或设置一个值,它可确定绑定源更新的时机。现在我们已经介绍了绑定目标、绑定就差绑定源了。
绑定源
在数据绑定中,绑定源对象是指用户从其获取数据的对象。
在这个demo中,绑定源是一个Person对象。
查看Person类的代码:
using <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>System.ComponentModel;namespace <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>SimpleBinding{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>This <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>class <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>implements <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>INotifyPropertyChanged <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>to <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>support <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>one-way <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>and <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>two-way <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>bindings <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>(such <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>that <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>the <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>UI <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>element <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>updates <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>when <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>the <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>source <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>has <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>been <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>changed <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>dynamically) <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>public <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>class <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Person <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>: <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>INotifyPropertyChanged <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>private <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>string <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>_name; <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>public <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Person() <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>} <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>public <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Person(string <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>value) <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>_name <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>= <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>value; <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>} <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>public <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>string <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PersonName <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>get <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>return <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>_name; <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>} <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>set <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>_name <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>= <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>value; <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Call <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>OnPropertyChanged <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>whenever <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>the <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>property <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>is <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>updated <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>OnPropertyChanged("PersonName"); <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>} <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>} <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Declare <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>the <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>event <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>public <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>event <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PropertyChangedEventHandler <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PropertyChanged; <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Create <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>the <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>OnPropertyChanged <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>method <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>to <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>raise <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>the <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>event <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>protected <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>void <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>OnPropertyChanged(string <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>name) <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>var <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>handler <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>= <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PropertyChanged; <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>handler?.Invoke(this, <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>new <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PropertyChangedEventArgs(name)); <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>} <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>}}首先这个Person类实现了INotifyPropertyChanged接口,我们来看下INotifyPropertyChanged接口:
public <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>interface <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>INotifyPropertyChanged{ <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>摘要: <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>// <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>Occurs <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>when <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>a <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>property <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>value <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>changes. <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/> <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>event <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PropertyChangedEventHandler? <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>PropertyChanged;}包含一个PropertyChanged事件,因此该Person类必须实现接口的成员PropertyChanged。
当属性值被设置时,会调用OnPropertyChanged方法,从而触发事件。
INotifyPropertyChanged接口定义了一个PropertyChanged事件,当一个属性的值发生变化时,你可以触发这个事件。WPF的数据绑定引擎会监听这个事件,当事件被触发时,它会更新绑定的UI元素的值。
如果你的数据源没有实现这个接口,那么当数据源的属性值发生变化时,WPF的数据绑定引擎将无法知道这个变化,因此它将无法更新UI元素的值。
这意味着,如果你的数据源的属性值在运行时可能会发生变化,并且你希望这些变化能够自动反映到UI上,那么你的数据源就需要实现INotifyPropertyChanged接口。
总结✨

通过这个小Demo,我们明白了WPF中的数据绑定的三要素,绑定对象、绑定、绑定源。在这个demo中,我们学会了如何在xaml中声明绑定,知道了Binding的三个属性Source、Path与UpdateSourceTrigger的含义,明白了数据源为什么要实现INotifyPropertyChanged接口,学会了WPF中数据绑定的基本用法,希望对你有所帮助。

来源:https://www.cnblogs.com/mingupupu/p/17994859
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 <TextBlock Text="{Binding Source={StaticResource MyDataSource}, Path=PersonName}"/>我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: 通过Demo学WPF—数据绑定(一)✨