“{Binding Path=.}”在 WPF 绑定中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1066262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "{Binding Path=.}" mean in WPF binding?
提问by Sergey Aldoukhov
What does {Binding Path=.}
mean in a WPF binding?
{Binding Path=.}
WPF 绑定中的含义是什么?
I see some people use it, but couldn't find any explanation.
我看到有些人使用它,但找不到任何解释。
Are there any other special symbols in binding syntax (other than {Binding /}
)?
绑定语法中是否还有其他特殊符号(除了{Binding /}
)?
采纳答案by micahtan
This is shorthand for binding to the current source. For more info see here.
这是绑定到当前源的简写。有关更多信息,请参见此处。
From the documentation specifically:
具体来自文档:
Optionally, a period (.) path can be used to bind to the current source. For example,
Text="{Binding}"
is equivalent toText="{Binding Path=.}"
.
可选地,可以使用句点 (.) 路径绑定到当前源。例如,
Text="{Binding}"
相当于Text="{Binding Path=.}"
。
回答by Ryan Versaw
I found this WPF Binding CheatSheeta few months back and find it very useful, especially for anyone learning WPF. There are some spelling mistakes within it, but it is still quite good.
几个月前我发现了这个WPF Binding CheatSheet并发现它非常有用,特别是对于任何学习 WPF 的人。里面有一些拼写错误,但它仍然很好。
Here is a small excerpt (which is supposed to have tabular formatting):
这是一小段摘录(应该具有表格格式):
Basic Binding
{Binding} Bind to current DataContext.
{Binding Name} Bind to the “Name” proeprty of the current DataContext.
{Bindind 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”.