Silverlight:绑定被多次调用
我有一个绑定到 DataContext
属性的 XAML 元素:
<ListBox ItemsSource="SectionViewModels" />
这绑定到一个属性:
public IList<SectionViewModel> SectionViewModels
{
get
{
// ...
}
}
加载页面时,即使我没有触发任何 PropertyChanged
事件。这是预料之中的,还是意味着我有一个错误?
(我正在 Windows Phone 7 上构建 Silverlight 应用程序。)
I have a XAML element that binds to a property of the DataContext
:
<ListBox ItemsSource="SectionViewModels" />
This binds to a property:
public IList<SectionViewModel> SectionViewModels
{
get
{
// ...
}
}
When the page is loaded, this property is called multiple times, even though I haven't fired any PropertyChanged
events. Is this to be expected, or does it mean I have a bug?
(I'm building a Silverlight app on Windows Phone 7.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在不深入了解问题的具体情况的情况下,您应该使用 ObservableCollection这类事情 - 如果您直接绑定到 Silverlight 或 WP7 中的集合,ObservableCollection 将消除您尝试自己创建跨线程绑定时要处理的 99.9% 的垃圾。
Without getting into the specifics of your issue, you should use an ObservableCollection for this sort of thing - if you're binding directly to a collection in Silverlight or WP7, an ObservableCollection will eliminate 99.9% of garbage you will deal with trying to create a cross-thread binding yourself.