Silverlight:绑定被多次调用

发布于 2024-10-09 12:09:28 字数 424 浏览 0 评论 0原文

我有一个绑定到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝情姑娘 2024-10-16 12:09:28

在不深入了解问题的具体情况的情况下,您应该使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文