【发布时间】:2010-11-07 03:59:04
【问题描述】:
{Binding Path=.} 在 WPF 绑定中是什么意思?
我看到有人使用它,但找不到任何解释。
绑定语法中是否还有其他特殊符号({Binding /} 除外)?
【问题讨论】:
标签: wpf data-binding xaml
{Binding Path=.} 在 WPF 绑定中是什么意思?
我看到有人使用它,但找不到任何解释。
绑定语法中是否还有其他特殊符号({Binding /} 除外)?
【问题讨论】:
标签: wpf data-binding xaml
几个月前我发现了这个WPF Binding CheatSheet,发现它非常有用,尤其是对于任何学习 WPF 的人。里面有一些拼写错误,但还是不错的。
这是一小段摘录(应该是表格格式):
| Basic Binding | |
|---|---|
| {Binding} | Bind to current DataContext. |
| {Binding Name} | Bind to the “Name” property of the current DataContext. |
| {Binding Name.Length} | Bind to the Length property of the object in the Name property of the current DataContext. |
| {Binding ElementName=SomeTextBox, Path=Text} | Bind to the “Text” property of the element XAML element with name=”SomeTextBox” or x:Name=”SomeTextBox”. |
【讨论】:
{Binding },但是我已经有好几年没有使用 Xaml 了,所以我不确定。
{Binding string} 类似于{Binding Path=string}。 string 不用于直接初始化属性Path,而是作为构造函数Binding (string path) 的参数,然后初始化Path 属性。这仅在字符串是Binding 之后的第一个标记时才有效,其余的是常规初始化程序(属性=值对)。知道这一点,Binding . 实际上等于Binding Path=. 并且属性路径语法可用here。
这是绑定到当前源的简写。欲了解更多信息,请参阅here。
具体来自文档:
(可选)句点 (.) 路径可用于绑定到当前 资源。例如,
Text="{Binding}"等价于Text="{Binding Path=.}"。
【讨论】: