绑定到类项目
这看起来应该是非常基本的,但我似乎无法让它工作。
我有一个名为 XMLSource 的类文件,如下所示:
Public Class XMLSource
Public Shared BrandItems As New MediaItems
Public Class MediaItems
Inherits ObservableCollection(Of MediaObject)
Implements INotifyPropertyChanged
End Class
End Class
Public Class MediaObject
Public Property Name As String
Public Property Title As String
End Class
应用程序读取 XML 文件并将一些项目存储到 XMLSource.BrandItems 中(在启动时发生)。
我想将 Label 控件的 Content 属性绑定到 XMLSource.BrandItems(0).Name
我尝试过:
<Label Content="{Binding Source={XMLSource},Path=.BrandItems[0].Src}" FontSize="20"></Label>
但它不起作用。
这样直接绑定可以吗?
This seems like it should be really basic but I can't seemto get it working.
I have a class file called XMLSource as follows:
Public Class XMLSource
Public Shared BrandItems As New MediaItems
Public Class MediaItems
Inherits ObservableCollection(Of MediaObject)
Implements INotifyPropertyChanged
End Class
End Class
Public Class MediaObject
Public Property Name As String
Public Property Title As String
End Class
The application reads an XML file and stores some items into XMLSource.BrandItems (happens on start-up).
I want to bind a Label control's Content property to XMLSource.BrandItems(0).Name
I tried:
<Label Content="{Binding Source={XMLSource},Path=.BrandItems[0].Src}" FontSize="20"></Label>
But it's not working.
Is it possible to bind directly like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您编写的
{}
指示 标记扩展,此外,绑定路径中不能有静态/共享成员。我认为正确的绑定是:x:Static
< /a> 是一个允许访问静态成员的标记扩展。 (请注意,这还允许访问与仅允许公共属性的Path
不同的字段)其中
ns
在xmlns
属性 并指向XMLSource
类的命名空间。You cannot contruct bindings like this, if you write
{}
that indicates a markup extension, further you cannot have static/shared members in a binding path. I think the correct binding would be:x:Static
is a markup extension which allows access of static members. (Note that this also allows access of fields unlike thePath
which only allows public properties)Where
ns
is declared in anxmlns
attribute and points to the namespace of yourXMLSource
class.