ItemsControl 绑定到 DataModel.ObservableCollection
我有一个绑定到 ViewModel 的视图 (MainPage.xaml)。 在 ViewModel 中,我有一个 DataModel 属性(请注意,viewmodel 和 datamodel 都实现了 INotifyPropertyChanged,或者该接口的名称)。
在我看来,我定义了一个 ItemsControl,其 ItemsSource 绑定到所述属性。这个属性(DataModel)有一个ObservableCollection(我知道它填充了有效数据)。
xaml 片段如下所示:
<ItemsControl ItemsSource="{Binding Path=CurrentDataModel.Items}">
请注意,我没有显示 xaml 的其余部分。它显示的只是 ItemsTemplate,它只是一个 TextBlock。
问题是,尽管我可以清楚地看到(在调试时)该集合具有良好的数据,但该 ItemsControl 没有绘制任何内容。
对于 ItemsControl 的 ItemsSource 来说,此“Path=...”绑定是否不可能?
I have a view (MainPage.xaml) which is bound to a ViewModel.
In the ViewModel I have a DataModel property (note that both viewmodel & datamodel implements INotifyPropertyChanged, or what that interface is called).
In my view i have defined an ItemsControl whose ItemsSource is bound to the said property. This property (DataModel) has an ObservableCollection (which i know it populated with valid data).
The xaml snippet looks like this:
<ItemsControl ItemsSource="{Binding Path=CurrentDataModel.Items}">
Note that i am not showing the rest of the xaml. All it shows is the ItemsTemplate which is just a TextBlock.
The issue is that nothing is being drawn for this ItemsControl, even though i can clearly see (while debugging) that the collection has good data.
Is this "Path=..." binding not possible for an ItemsControl's ItemsSource?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
路径语法看起来正确。最可能的失败原因是
DataContext
未设置为您的ViewModel
或者您指定的属性路径不正确。在您的问题中,您声明
ViewModel
有一个名为 DataModel 的属性,但在 xaml 代码片段中您有CurrentDataModel
。The Path syntax looks correct. The most likely cause of failure is that either the
DataContext
is not set to yourViewModel
or that the property path you specified is incorrect.In your question you state that the
ViewModel
has a property named DataModel but in the xaml snippet you haveCurrentDataModel
.