WPF PRISM 重新加载模块不更新视图

发布于 2024-08-26 21:08:35 字数 452 浏览 3 评论 0原文

我遇到过这样的情况:当用户单击按钮时,我将 WPF PRISM 模块加载到程序中。该程序查看已加载模块上的 ComboBox SelectedItem 属性,为新模块的数据上下文选取数据。然后它将数据从数据库加载到新模块的数据上下文中。这将在新模块的视图上设置我的数据绑定控件的属性。

现在,当我再次关闭(卸载)该模块,然后从组合框中取出另一个项目并重新加载该模块时,该模块的上下文将填充正确的数据,但我在此模块中的视图未更新。

我已经在绑定到该模块上的控件的属性上实现了 INotifyPropertyChanged,但是它们似乎不会自动更新。从第一次加载该模块以来的旧数据似乎保留在控件中。

仅当我在卸载时将已加载模块的数据上下文设置回 NULL,然后重新加载时,它才会更新模块的视图。

然而,这感觉就像是黑客攻击,而不是真正应该的样子。有谁知道为什么当上下文中的数据在重新加载后发生变化时,该模块的视图似乎没有自动更新?

I have a situation where I load a WPF PRISM module into the program when the user clicks a button. The program looks at a ComboBox SelectedItem property on the already loaded module to pick data for the datacontext of the new module. Then it loads data from a database into the datacontext of the new module. This sets the properties of my databound controls on the new module's view.

Now when I close (unload) this module again, then take another item from my Combobox and reload the module, the context of the module fills with correct data, but my view in this module is not updated.

I have implemented INotifyPropertyChanged on the properties bound to the controls on this module, however they do not seem to update automatically. The old data, from the first time this module was loaded, seem to stay in controls.

Only when I set my datacontext of the loaded module back to NULL on unloading, and then relaod it updates the view of the module.

This however feels like a hack, not really how it's supposed to be. Does anybody have any idea why the view of this module does not seem to update itself when the data in the context changes after reloading?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

千柳 2024-09-02 21:08:35

我(可能很简单)的理解是,视图不会收到 DataContext 更改的通知(您只在属性上有 PropertyChanged,而不是在 DataContext 上)。

但您可能还想查看

http: //blogs.msdn.com/b/delay/archive/2010/05/11/we-ve-secretly-changed-this-control-s-datacontext-let-s-see-if-it-notices-workaround- for-a-silverlight-数据绑定-bug-影响-各种-场景-包括-datagrid-contextmenu.aspx

My (probably simplistic) understanding is that the view is not notified of DataContext changed (you only have PropertyChanged on properties not on the DataContext).

But you might also want to look at

http://blogs.msdn.com/b/delay/archive/2010/05/11/we-ve-secretly-changed-this-control-s-datacontext-let-s-see-if-it-notices-workaround-for-a-silverlight-data-binding-bug-affecting-various-scenarios-including-datagrid-contextmenu.aspx

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