绑定表达式
流行的数据绑定表达式
数据上下文绑定
在WPF中每个控件都有一个DataContext属性。它应该绑定到要显示的数据的对象。DataContext属性被逻辑树层层继承。
- {Binding} 绑定DataContext对象
- {Binding Name} 绑定DataContext对象的Name属性
- {Binding Name.Length} 绑定DataContext对象的Name属性的Length属性
相对绑定
绑定的相对源扩展帮你用相对关系绑定对象。你不需要知道你的或它的绝对位置,但是你知道它的上层或者下层结点是什么,或者在它的层级之上某个指定类型。
- {Binding RelativeSource={RelativeSource Self}}
绑定你自己。帮你你访问你自己的属性 - {Binding Text, RelateveSource={RelativeSource Self}}
绑定目标元素的Text属性 - {Binding ISSelected, RelativeSource={RelativeSourceMode=FindAncestor,AncestoryType={x:Type ListBoxItem}}}
绑定ListBoxItem类型的父元素的IsSelected属性
集合当前项的绑定
斜杠让你访问集合视图的特别的操作
- {Binding /} 绑定到DataContext中的集合当前项
- {Binding Customers/} 从数据上下文中的Customer属性绑定到集合的当前项(?)
- {Binding Customers/Name} 绑定到DataContext的Customers集合当前项的Name属性