转载:WPF binding
<StackPanel><TextBlock Width="248" Height="24" Text="Colors:" TextWrapping="Wrap"/><ListBox x:Name="lbColor" Width="248" Height="56"><ListBoxItem Content="Blue"/><ListBoxItem Content="Green"/><ListBoxItem Content="Yellow"/><ListBoxItem Content="Red"/><ListBoxItem Content="Purple"/><ListBoxItem Content="Orange"/></ListBox><TextBlock Width="248" Height="24" Text="You selected color:" /><TextBlock Width="248" Height="24"><TextBlock.Text><Binding ElementName="lbColor" Path="SelectedItem.Content"/></TextBlock.Text></TextBlock> </StackPanel>
<TextBlock Width="248" Height="24" Text="{Binding ElementName=lbColor, Path=SelectedItem.Content}" />
<TextBlock Width="248" Height="24" Text="{Binding ElementName=lbColor, Path=SelectedItem.Content, Mode=OneWay}" x:Name="tbSelectedColor" Background="{Binding ElementName=lbColor, Path=SelectedItem.Content, Mode=OneWay}"/>
<TextBlock Width="248" Height="24" Text="{Binding ElementName=lbColor, Path=SelectedItem.Content,Mode=OneWay}" x:Name="tbSelectedColor" Background="{Binding ElementName=lbColor, Path=SelectedItem.Content, Mode=OneWay}"/> <TextBox Width="248" Height="24" Text="{Binding ElementName=lbColor, Path=SelectedItem.Content, Mode=TwoWay}" x:Name="txtSelectedColor" Background="{Binding ElementName=lbColor, Path=SelectedItem.Content, Mode=OneWay}"/>
<StackPanel> <StackPanel.Resources> <XmlDataProvider x:Key="MoreColors" XPath="/colors"><x:XData><colors ><color name="pink"/><color name="white"/><color name="black"/><color name="cyan"/><color name="gray"/><color name="magenta"/></colors></x:XData> </XmlDataProvider>
<ListBox x:Name="lbColor" Width="248" Height="56" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Source={StaticResource MoreColors}, XPath=color/@name}"> </ListBox>
<XmlDataProvider x:Key="Colors" Source="Colors.xml" XPath="/colors"/>
<ListBox x:Name="lbColor" Width="248" Height="56" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Source={StaticResource Colors}, XPath=color/@name}"> </ListBox>
<StackPanel.Resources> <ObjectDataProvider x:Key="persons" ObjectType="{x:Type svc:PersonService}" MethodName="GetPersonList"></ObjectDataProvider> </StackPanel.Resources>
xmlns:svc="clr-namespace:DataBindingWPF"
<Window x:Class="DataBindingWPF.ObjectBinding" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:svc="clr-namespace:DataBindingWPF" Title="DataBindingWPF" Height="300" Width="300"> <StackPanel><StackPanel.Resources><ObjectDataProvider x:Key="persons" ObjectType="{x:Type svc:PersonService}" MethodName="GetPersonList" ></ObjectDataProvider><DataTemplate x:Key="personLayout" DataType="Person"><StackPanel Orientation="Vertical"><TextBlock Text="{Binding Path=FullName}" FontWeight="Bold" Foreground="Blue"></TextBlock><StackPanel Orientation="Horizontal"><TextBlock Text="{Binding Path=Title}"></TextBlock><TextBlock Text=", "></TextBlock><TextBlock Text="{Binding Path=City}"></TextBlock></StackPanel></StackPanel></DataTemplate></StackPanel.Resources><TextBlock></TextBlock><ListBox x:Name="lbPersons" ItemsSource="{Binding Source={StaticResource persons}}" ItemTemplate="{DynamicResource personLayout}" IsSynchronizedWithCurrentItem="True"/> </StackPanel> </Window>
<CollectionViewSource x:Key="personView" Source="{Binding Source={StaticResource persons}}"><CollectionViewSource.SortDescriptions><ComponentModel:SortDescription PropertyName="City" Direction="Ascending" /> <ComponentModel:SortDescription PropertyName="FullName" Direction="Descending" /></CollectionViewSource.SortDescriptions> </CollectionViewSource>
<StackPanel> <TextBlock Text="{Binding Source={StaticResource personView}, Path=FullName}"></TextBlock> <TextBlock Text="{Binding Source={StaticResource personView}, Path=Title}"></TextBlock> <TextBlock Text="{Binding Source={StaticResource personView}, Path=City}"></TextBlock> </StackPanel>
<StackPanel DataContext="{Binding Source={StaticResource personView}}" > <TextBlock Text="{Binding Path=FullName}"></TextBlock> <TextBlock Text="{Binding Path=Title}"></TextBlock> <TextBlock Text="{Binding Path=City}"></TextBlock> </StackPanel>
转载于:https://www.cnblogs.com/fanguizhang/archive/2012/08/16/Binding.html
转载:WPF binding相关推荐
- WPF入门教程系列(二) 深入剖析WPF Binding的使用方法
同一个对象(特指System.Windows.DependencyObject的子类)的同一种属性(特指DependencyProperty)只能拥有一个binding. 这一点可以通过设置bindi ...
- WPF Binding(四种模式)
WPF Binding(四种模式) 在使用Binding类的时候有4中绑定模式可以选择 BindingMode TwoWay 导致对源属性或目标属性的更改可自动更新对方.此绑定类型适用于可编辑窗体或其 ...
- WPF Binding(绑定)详解
Binding概念理解: WPF为了实现了UI与数据逻辑的解耦,将UI从数据逻辑中分离出来形成Xaml文件,而UI与数据逻辑之间的联系则通过Bingding来实现.Bingding就像UI与数据逻辑之 ...
- 为什么这儿TemplateBinding不起作用了—研究WPF Binding(一)
工作中,写自定义控件,遇到一个奇怪的问题.场景是这样的:一个ListBox或其他ItemsControl显示数据列表,下方一个TextBlock显示列表中选定的值,代码大概是这样的(做了简化): &l ...
- [转载]WPF – 使用触发器
WPF提供了很重要的一个东西就是绑定Binding, 它帮助我们做了很多事情,这个我们在WPF学习之绑定这篇里边有讲过.对于Binding我们可以设置其绑定对象,关系,并通过某种规则去验证输入,或者转 ...
- WPF Binding
Binding的亮点 在WPF中,Binding无处不在,关于Binding的漂亮用法有很多,其主要的设计亮点有二: Weak Event模式 Converter 监听B的属性变化,A需要注册B的Pr ...
- Wpf Binding.Path设置
Binding.Path 获取或设置绑定源属性的路径. 每个绑定通常都具有四个组件:绑定目标对象.目标属性.绑定源,以及要使用的绑定源值的路径.有关这些数据绑定概念的更多信息,请参见数据绑定概述. 使 ...
- 转载 WPF 控件模板 数据模板 面板模板
转载自:https://blog.csdn.net/ceasadan/article/details/61414879 模板使用方式:首先定义模板,然后在把对应的key应用到控件对应的属性中: 属性对 ...
- [转载]WPF控件拖动
这篇博文总结下WPF中的拖动,文章内容主要包括: 1.拖动窗口 2.拖动控件 Using Visual Studio 2.1thumb控件 2.2Drag.Drop(不连续,没有中间动画) 2.3拖动 ...
最新文章
- 在yii2中,让你action参数支持POST数据的小方法
- 使用c语言读写netcdf文件,[原][c][netcdf]读取函数
- UVA 141 The Spot Game
- Netflix在安卓移动启用AV1格式 较VP9编码效率提升20%
- c#语言中读取txt文件,简单的c#文本文件读写-.NET教程,C#语言
- XXX集团财务决策支持系统——财务分析指标(系列五)
- 批量修改数据_#泰Q头条#065期 四步搞定Excel表中的批量数据修改
- Linux下dd查看磁盘的读写性能
- iPhone 12再陷“信号门”:用户称每天需多次重启恢复;蚂蚁集团打新资金退款如期到账;Mutt 2.0 发布|极客头条
- linux中用shell获取时间,日期
- java常见面试题:Java程序员面试题(五)
- 测试时的一些技巧及面试官的一些期望回答
- matlab textscan溢出,matlab - Textscan存档有大量的行 - 堆栈内存溢出
- dell电脑装双系统linux,戴尔电脑怎么装双系统?戴尔装win7+win10双系统详细教程
- 从头到尾彻底解析Hash 表算法
- 【超快捷】Windows系统自带的快捷键合集
- wpf 打开输入法、禁用输入法
- chfs http 文件共享服务
- ForestBlog博客源码学习笔记
- 写给还在迷茫中的朋友,一名6年程序员的工作感悟!!!