WPF 将 ItemsSource 绑定到静态方法?
我在名为“Article”的类中有以下静态方法:
public static ObservableCollection<Article> GetObservableCollection() { ... }
我想将其直接绑定到 ComboBox 的 ItemsSource 属性,但在 XAML 中而不是在代码中,我找不到正确的语法。
我认为它应该看起来像这样(EmacGbscCore 是包含 Article 对象的程序集):
ItemsSource="{Binding Source={x:Static EmacGbscCore:Article.GetObservableCollection}}"
提前感谢您的帮助。
I have the following static method in an class called "Article" :
public static ObservableCollection<Article> GetObservableCollection() { ... }
And I'd like to bind this directly to the ItemsSource property of a ComboBox but in the XAML not in code, I can't find the right syntax.
It should look something like this I think (EmacGbscCore is the assembly containing Article object) :
ItemsSource="{Binding Source={x:Static EmacGbscCore:Article.GetObservableCollection}}"
Thank in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在资源中声明一个
ObjectDataProvider
:并将其用作绑定的源:
You need to declare an
ObjectDataProvider
in the resources:And use this as the source of your binding: