WPF/Silverlight - 跨多个 XAML 绑定
。
大家好,
考虑一下 Prism(WPF/Silverlight)的常见场景,其中我们有多个区域,每个区域都有一个视图(XAML),因此当我们使用鼠标与一个视图(XAML)交互时可能会出现一种情况或键盘,我们可能想要相应地更改或更新其他视图(恰好是不同 XAML)。例如,从视图(例如 ItemPanelView)中选择一个项目时,我们可能希望在其他视图(例如 ItemDetailsView)中显示所选项目的详细信息。
所以我的问题是,
将一个视图 (XAML) 中的元素绑定到其他视图(不同 XAML)中的元素来实现此类功能是否是一个好主意?如果我没记错的话,使用这种方法,我们不需要从一个演示者转到另一个演示者(使用 TwoWay 绑定等),以便更新其他区域中的视图。
或者,有没有优雅而简单的方法来做到这一点?
。
.
Hello guys,
Consider the usual scenario of Prism (WPF/Silverlight) in which we've multiple regions, and in each goes a view (XAML), so a situation might arise when we interact with one view (XAML), either using mouse, or keyboard, we may want to change or update other views (which happen to be different XAMLs) accordingly. For example, on selecting an item from a view, say ItemPanelView, we may want to show the details of the selected item in other view, say ItemDetailsView.
So my question is,
Would it be a good idea to bind elements from one view (XAML), to the elements in the other views (different XAMLs), to implement such functionalities? If I'm not wrong, using this approach we would not need to go from one presenter to other (using TwoWay bindings etc), so as to update the view in other region.
Or, is there any elegant yet simple way to do this?
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您查看 Prism 的 EventAggregator (http://blogs.msdn.com/b/francischeung/archive/2008/06/02/de Coupled-communication-with-prism-event-aggregation.aspx)。您的每个视图(或者最好是视图可以使用触发器响应/更新的视图模型)都可以订阅/发布共享事件。但是,我建议不要简单地响应鼠标单击或键盘事件来引发此共享事件,而是使共享事件有意义(即 MyItemSelected 或 MyItemHidden)。如果您需要更多帮助或澄清,请告诉我。
I suggest you take a look at the Prism's EventAggregator (http://blogs.msdn.com/b/francischeung/archive/2008/06/02/decoupled-communication-with-prism-event-aggregation.aspx). Each of your views (or preferably view models to which views can respond/update using triggers) can subscribe to / publish a shared event. However, I suggest that instead of simply responding to a mouse click or keyboard event to raise this shared event, make the shared event meaningful (i.e. MyItemSelected or MyItemHidden). If you need more assistance or clarification with this, let me know.
有多种方法可以在不违反 PRiSM 规范概念的情况下做到这一点。
正如 [MSDN 文档][1](第 9 章:松散耦合组件之间的通信)告诉我们:
在模块之间进行通信时,了解方法之间的差异非常重要,以便您可以最好地确定在您的特定情况下使用哪种方法设想。 Prism 库提供以下通信方法:
在您的情况下,您应该使用 EventAggregator 或 RegionContext。共享 ViewModel 是可能的,但这是最后的手段。
There are several ways to do that without breaking canonical concept of the PRiSM.
As [MSDN docs][1] (Chapter 9: Communicating Between Loosely Coupled Components) tell us:
When communicating between modules, it is important that you know the differences between the approaches so that you can best determine which approach to use in your particular scenario. The Prism Library provides the following communication approaches:
In your case you should use EventAggregator or RegionContext. Shared ViewModel is possible but this is the last resort.