将对象列表绑定到 WPF ListView
我有一个对象列表,我想将其绑定到 WPF 应用程序中的 ListView 控件。 对象已经有一个 DataTemplate,所以不需要定义它。
对象列表是代码隐藏文件中的属性,格式为 list
<ListBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Portfolios}"/>
我尝试绑定的属性名称是 Portfolios 并且存在于父窗口中
I have a list of objects which i want to bind to a ListView control in my WPF application.
The Objects have a DataTemplate already, so no need to define that.
The list of objects is a property in the codebehind file in the format list<object>
When i add one object programatically, it appears fine. But when i try to bind the ItemSource of the ListBox to the list of objects, nothing shows up.
I am using the following binding:
<ListBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Portfolios}"/>
where the name of the property i am trying to bind to is Portfolios and exists on the parent window
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加新项目时,
List
对象不会自动报告。尝试使用ObservableCollection<>
来代替,看看是否有帮助。List<>
objects don't automatically report when a new item is added. Try using anObservableCollection<>
instead, and see if that helps.