带/不带“Path=”的 Silverlight 绑定句法
指定属性的绑定时何时需要“Path=”xaml 语法? 当存在嵌套属性绑定时(例如:Path=Person.FirstName),我几乎只看到这个“Path=”。
谢谢!
When is the "Path=" xaml syntax required when specifying a binding to a property?
I see this "Path=" pretty much exclusively when there is a nested property binding (ex: Path=Person.FirstName).
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以将其想象为在 C# 中初始化一个类。如果“Binding”类有一个采用路径的构造函数,您可以这样做:
... 或这样:
无论出于何种意图和目的,这两者都是相同的。 XAML 也在做同样的事情。如果省略“Path=”,则会将路径传递到绑定的构造函数中,但如果包含它,则会在事后设置值。
我经常省略“Path=”,特别是当我声明没有设置其他属性的绑定时,例如
{Binding FirstName}
。Think of it like initializing a class in C#. If the "Binding" class has a constructor that takes a path, you could do this:
... or this:
The two are the same, for all intents and purposes. XAML is doing the same thing. If you omit the "Path=" you're passing a path into the constructor for Binding, but if you include it you're setting the value after the fact.
I often leave the "Path=" out, especially if I'm declaring a binding with no other properties set, like
{Binding FirstName}
.当您绑定到的对象与设置到控件的 DataContext 属性的对象不同时,可以使用此选项
You use this when the object you are binding to is not the same object that is set to the control's DataContext property