简体   繁体   中英

WPF GUI object sharing (PRISM/MEF)

I have created a prism project consisting of two modules (dll's). The two modules are loaded within a shell and build up following the MVVM pattern.

Module1 receives data which should be transferred (as fast as possible) to Module2. This data could be stored in an observablecollection for example. Which means that if this observablecollection is updated it should update the view in module2. It is a lot of data, so I would not use the eventaggregator for that.

I read something about dependency injection but I'm not sure how to do it. I found several examples where a submit button was pushed to transfer data between two modules. I guess what I need would be somehow a reference of the observablecollection(module1) within the module2. Shared services is another keyword I found.

What would be a good solution to solve this?

An example with an mvvm pattern would be great. I'm new to prism so please be kind.

There is nothing wrong with using events for such task. It is a common practice to have some interface:

interface IDataReciever<TData>
{
    event Action<TData> DataRecieved;
    //some other methods, such as, for example:
    //void Open();
    //void Close();
}

hinding all the interactions with serial port. You can then pass this interface to your viewmodel constructor, subscribe to event and add data to observable collection (converting it to some model if needed) in the event handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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