Binding ,抄自 http://www.cnblogs.com/cnblogsfans/archive/2011/02/19/1958586.html
1. 绑定到其它元素
<Grid>
<StackPanel >
<TextBox x:Name="textBox1" Height="150" BorderBrush="Black" BorderThickness="10"/>
<Label Content="{Binding ElementName=textBox1,Path=Text}"/>
</StackPanel>
</Grid>
2. 绑定到静态资源
<Window.Resources>
<ContentControl x:Key="FirstKey">Hello World!</ContentControl>
</Window.Resources>
<Grid>
<StackPanel>
<Label x:Name="label1" Content="{Binding Source={StaticResource ResourceKey=FirstKey}}"/>
</StackPanel>
</Grid>
3.绑定到自身
<StackPanel>
<Label x:Name="label45347356736" BorderBrush="Black" Width="1200" Content="{Binding RelativeSource={RelativeSource Self},Path=Width}"/>
</StackPanel>
4.绑定到指定类型的父元素
<Grid x:Name="Grid1">
<StackPanel>
<Label x:Name="label1" Content="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}},Path=Name}"/>
</StackPanel>
</Grid>
5. 绑定到对象
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
<StackPanel x:Name="stackPanel">
<StackPanel.DataContext>
<local:Person Name="Fred" Age="29"/>
</StackPanel.DataContext>
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock Text="{Binding Path=Age}"/>
</StackPanel>
6. 绑定到集合
<Window.Resources>
<local:PersonList x:Key="person">
<local:Person Name="Fred" Age="30"/>
<local:Person Name="ZFF" Age="30"/>
</local:PersonList>
</Window.Resources>
<StackPanel x:Name="stackPanel">
<ListBox ItemsSource="{Binding Source={StaticResource ResourceKey=person}}" DisplayMemberPath="Name"/>
</StackPanel>
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
public class PersonList:ObservableCollection<Person>
{
}
8.DataContext共享源
WPF 提供了一个称之为 "数据上下文 (DataContext)" 的东西让我们可以在多个元素上共享一个源对象,只需将其放到父元素 DataContext 属性即可。当我们不给 Binding 扩展标志指定 Source 属性时,它会自动寻找上级父元素的数据上下文。
<
StackPanel
>
<
ListView
x:Name="personListView">
<
ListView.View
>
<
GridView
>
<
GridViewColumn
Header="Id" Width="100"
DisplayMemberBinding="{Binding XPath=@Id}"/>
<
GridViewColumn
Header="Name" Width="100"
DisplayMemberBinding="{Binding XPath=Name}"/>
</
GridView
>
</
ListView.View
>
</
ListView
>
<
Button
Click="Button_Click">Load Data</
Button
>
</
StackPanel
>
private void btn_Click(object sender, RoutedEventArgs e)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"E:\Work\20150516\WpfApplication368\WpfApplication368\FirstXML.xml");
XmlDataProvider xdp = new XmlDataProvider();
xdp.Document = xmlDocument;
xdp.XPath = @"/PersonList/Person";
this.personListView.DataContext = xdp;
this.personListView.SetBinding(ListView.ItemsSourceProperty, new Binding());
}
Binding ,抄自 http://www.cnblogs.com/cnblogsfans/archive/2011/02/19/1958586.html的更多相关文章
- delphi 颜色 引用http://www.cnblogs.com/del/archive/2008/02/19/1073568.html
颜色名称 颜色效果 Hex HTML clBlack $000000 #000000 clMaroon $000080 #800000 clGreen $008000 #00800 ...
- c# 和 java <转载>http://www.cnblogs.com/zhucai/archive/2011/02/16/csharp-compare-java.html
从语法层面来讲,c# 和 java 是非常相似的. <转载> 这篇文章对C#与Java做一个语言级的对比,方便C#转Java或Java转C#的人有个大致了解.这里大致用C#3.0与Java ...
- http://www.cnblogs.com/youring2/archive/2011/03/28/1997694.html
http://www.cnblogs.com/youring2/archive/2011/03/28/1997694.html
- http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html
http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html
- ArcEngine中打开各种数据源(WorkSpace)的连接http://www.cnblogs.com/feilong3540717/archive/2011/08/07/2129906.html
ArcEngine中打开各种数据源(WorkSpace)的连接 ArcEngine中打开各种数据源(WorkSpace)的连接 (SDE.personal/File.ShapeFile.CAD数据.影 ...
- http://www.cnblogs.com/xwdreamer/archive/2012/02/21/2360818.html
http://www.cnblogs.com/xwdreamer/archive/2012/02/21/2360818.html
- http://www.cnblogs.com/yyyyy5101/archive/2011/03/11/1981078.html
http://www.cnblogs.com/yyyyy5101/archive/2011/03/11/1981078.html
- http://www.cnblogs.com/gaojing/archive/2011/08/23/2413616.html
http://www.cnblogs.com/gaojing/archive/2011/08/23/2413616.html
- http://www.cnblogs.com/TankXiao/archive/2012/02/06/2337728.html
http://www.cnblogs.com/TankXiao/archive/2012/02/06/2337728.html
随机推荐
- LinuxShell脚本——函数
LinuxShell脚本——函数 摘要:本文主要学习了Shell中函数的定义和使用. 函数的定义 Shell函数的本质是一段可以重复使用的脚本代码,这段代码被提前编写好了,放在了指定的位置,使用时直接 ...
- 计科菜鸟玩生信(一)——Windows10下用docker安装GATK
1.官网下载GATK. (学校网速实在是太慢了,下载几个小时到自闭) 下载地址:https://software.broadinstitute.org/gatk/download/ 下载完成后文件夹中 ...
- java基础第十五篇之IO流和递归算法
FileInputStream : 输入流 int available() : 一次读取所有的字节数 read() : 将文件上的字节读取到内存的数组中 FileOutputStream : 输出流 ...
- 设置view的layer属性方法
1.需要导入QuartzCore.framewoork框架到工程2.在文件中导入#import 3.设置 必须导入的空间 #import<QuartzCore/QuartzCore.h> ...
- Django 的ORM 表间操作
Django之ORM表间操作 之前完成了简单的数据库数据增加操作.这次学习更多的表间操作. 单表操作 增加 方式一 b = Book(title="Python基础", pub ...
- day35作业
1. 查询所有大于60分的学生的姓名和学号 (DISTINCT: 去重) -- 2.查询每个老师教授的课程数量 和 老师信息 -- 3. 查询学生的信息以及学生所在的班级信息 -- 4.学生中男生的个 ...
- 在ubuntu15.10上编译arm-linux环境使用的log4c步骤
步骤: 1.下载log4c源码 2.解压源码包,我解压后的路径是:/home/cc/Downloads/log4c-1.2.4 3.执行以下shell脚本: #!/bin/sh mkdir /home ...
- nginx 文件服务器配置,模板配置文件,有注释
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/e ...
- Python推导表达式、迭代器、生成器、模块和包
推导表达式 yield用法 模块的概念和导入方法 包和包管理 推导表达式(利用for,一个一个地放入数据) 列表推导 集合推导 字典推导 迭代器 迭代 for 迭代变量 in 可迭代对象 每一次循环都 ...
- centos安装php5、卸载php、安装php7
这篇文章主要介绍了centos安装php5.卸载php.安装php7 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 首先安装php5很简单 yum install php 然后如果不 ...