xaml:

<Window x:Class="WpfApplication1.Window4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window4" Height="371" Width="507">
<Grid>
<StackPanel Margin="10,10,12,12" Name="stackPanel1">
<TextBox Height="23" Margin="10" Name="textBox1" Width="120" />
<TextBox Height="23" Margin="10" Name="textBox2" Width="120" />
<TextBox Height="23" Margin="10" Name="textBox3" Width="120" />
</StackPanel>
</Grid>
</Window>

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.Shapes; namespace WpfApplication1
{
/// <summary>
/// Window4.xaml 的交互逻辑
/// </summary>
public partial class Window4 : Window
{
public Window4()
{
InitializeComponent();
List<Contry> infos = new List<Contry>()
{
new Contry() {
Name = "中国",
Provinces= new List<Province>(){ new Province(){
Name="四川",
Citys=new List<City>(){
new City(){
Name="绵阳市"
}}}}}};
this.textBox1.SetBinding(TextBox.TextProperty, new Binding("/Name") { Source=infos});
this.textBox2.SetBinding(TextBox.TextProperty, new Binding("/Provinces/Name") { Source = infos });
this.textBox3.SetBinding(TextBox.TextProperty, new Binding("/Provinces/Citys/Name") { Source = infos });
}
} class City
{
public string Name { set; get; }
} class Province
{
public string Name { set; get; }
public List<City> Citys { set; get; }
} class Contry
{
public string Name { set; get; }
public List<Province> Provinces { get; set; }
}
}

WPF 绑定四(层级绑定)的更多相关文章

  1. [WPF 基础知识系列] —— 绑定中的数据校验Vaildation

    前言: 只要是有表单存在,那么就有可能有对数据的校验需求.如:判断是否为整数.判断电子邮件格式等等. WPF采用一种全新的方式 - Binding,来实现前台显示与后台数据进行交互,当然数据校验方式也 ...

  2. 【WPF学习】第二十九章 元素绑定——将元素绑定到一起

    数据banding的最简单情形是,源对象时WPF元素而且源属性是依赖性属性.前面章节解释过,依赖项属性具有内置的更改通知支持.因此,当在源对象中改变依赖项属性的值时,会立即更新目标对象中的绑定属性.这 ...

  3. ASP.NET MVC Model绑定(四)

    ASP.NET MVC Model绑定(四) 前言 前面的篇幅对于Model绑定器IModelBinder以及实现类型.Model绑定器提供程序都作了粗略的讲解,可以把Model绑定器想象成一个大的容 ...

  4. WPF窗体视图中绑定Resources文件中字符串时,抛出:System.Windows.Markup.StaticExtension

    问题描述: 在Resources.resx定义了一个静态字符串字段Title,并在WPF窗体视图中绑定为窗体的标题: Title="{x:Static local:Resources.Tit ...

  5. this的四种绑定形式

    一 , this的默认绑定 当一个函数没有明确的调用对象的时候,也就是单纯作为独立函数调用的时候,将对函数的this使用默认绑定:绑定到全局的window对象. 一个例子 function fire ...

  6. WPF 在事件中绑定命令(不可以在模版中绑定命令)

    其实这也不属于MVVMLight系列中的东东了,没兴趣的朋友可以跳过这篇文章,本文主要介绍如何在WPF中实现将命令绑定到事件中. 上一篇中我们介绍了MVVMLight中的命令的用法,那么仅仅知道命令是 ...

  7. WPF PasswordBox不支持绑定解决方法

    原文:WPF PasswordBox不支持绑定解决方法 PasswordBox的Password属性因为安全原因不支持直接绑定,可以使用依赖属性实现.直接插入代码 public class Passw ...

  8. jQuery 事件绑定四种方式,delegate委托强大绑定在3.0中修改为on

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. WPF自定义控件的自定义属性绑定后不更新问题

    原文:WPF自定义控件的自定义属性绑定后不更新问题 需要在绑定时设置属性变更触发 UpdateSourceTrigger=PropertyChanged 例如: <Border CornerRa ...

随机推荐

  1. K - Ancient Messages(dfs求联通块)

    K - Ancient Messages Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

  2. D. Ilya and Escalator

    D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. 【MongoDB】增删改查基本操作

    查看所有数据库 show dbs 切换数据库(若不存在,会自动创建) use databasename 删除当前数据库 db.dropDatabase() MongoDB中没有表,只有集合. 插入集合 ...

  4. 《UNIX环境高级编程》学习心得 三

    输入和输出 1.文件描述符 文件描述符(file descriptor)可以理解为内核在某个进程中访问一个文件时,内核向进程返回的一个非负整数.在内核使用open或creat打开一个现有文件或者创建一 ...

  5. Redis中的批量删除数据库中的Key

    本文参考:http://blog.csdn.net/spring21st/article/details/15771861 http://stackoverflow.com/questions/575 ...

  6. 社区APP “钱途”漫漫

    花样年曾宣称:2013年“彩生活”物业品牌收入1.85亿,毛利率超过40%:万科万客会APP.龙湖物业APP……大量房地产企业依托物业企业,纷纷瞄准移动互联网.云计算.物联网等高新科技为基础的物业服务 ...

  7. PHP与MySQL中编码的设置

    php代码 header("Content-type:text/html;Charset=utf8"); myql_query("set names utf8" ...

  8. MyElcipse之问题小结

    运行MyEclipse时,遇到这一错误提示: An internal error occurred during: "Launching chat on MyEclipse Tomcat & ...

  9. JavaScript之简易计算器

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  10. 如何安装 JAVA 7 (JDK 7u75) 在 CentOS/RHEL 7/6/5 Fedora

    先下载JDK For 64 Bit:- # cd /opt/ # wget --no-cookies --no-check-certificate --header "Cookie: gpw ...