简体   繁体   English

EventAggregator或UriQuery哪个是传递数据的首选

[英]EventAggregator or UriQuery which one is preferred for passing data

I am using WPF Prism for our development and we want to pass values from one view/view model to another view/view model and we can use either EventAggregator or UriQuery, so need suggestion which one to use. 我正在使用WPF Prism进行开发,我们希望将值从一个视图/视图模型传递到另一视图/视图模型,并且可以使用EventAggregator或UriQuery,因此需要建议使用哪个。

Right now we can think of passing simple parameter like IDs.May be later on we have to pass objects but I know I cant directly pass object to uri query but we can manage it but passing fields. 现在我们可以考虑传递像ID这样的简单参数了。可能以后需要传递对象,但是我知道我不能直接将对象传递给uri查询,但是我们可以管理它但可以传递字段。

I know how to implement these but wanted to know which one is preferable way or standard in Prism and MVVM. 我知道如何实现这些,但想知道在Prism和MVVM中哪种方法或标准是更可取的。

Please suggest 请建议

It is largely down to taste as both methods work . 两种方法都起作用时,很大程度上难以品尝。

I reserve UriQuery for navigation that involves a payload. 我将UriQuery保留用于涉及有效载荷的导航。 This is the case in which UriQuery is discussed in the prism documentation . 这是在棱镜文档中讨论 UriQuery的情况。 I don't like them because they use weakly typed data - in this case strings. 我不喜欢它们,因为它们使用弱类型的数据-在这种情况下为字符串。 You have to serialise and deserialise. 您必须序列化和反序列化。 For complex data, this is error prone. 对于复杂数据,这容易出错。

An aggregated event lets you pass a Argument object when you publish the event. 聚合事件使您可以在发布事件时传递Argument对象。 You do not have to serialise and deserialise the query but you will need a common library to define the argument class. 您不必序列化和反序列化查询,但是您将需要一个公共库来定义参数类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM