简体   繁体   中英

How to get MVVM Light Messenger working with a PCL

I am currently reorganizing my WP8 project in order to have a Portable Class Library, which could result in a W8 app.

I am using MVVMLight and have the following code:

In the Portable Class Library:

namespace MyApp.Shared.Messages
{
    public class MyItemSelectedMessage : MessageBase
    {
        public MyItemSelectedMessage(MyItem item)
        {
            Item = item;
        }
        public MyItem Item { get; set; }
    }
}

In my WP8 app, I still do have the ViewModels (because of Telerik and some other stuff which I cannot outsource to the PCL), where I use the following code to register for the message:

Messenger.Default.Register<MyItemSelectedMessage>(this, msg => SelectedItem = msg.Item);

The code worked fine before but now VS gives me the following error in the WP8 app at the given line:

The type 'GalaSoft.MvvmLight.Messaging.MessageBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'GalaSoft.MvvmLight, Version=4.2.30.16997, Culture=neutral, PublicKeyToken=null'

In my WP8 project, I have installed MvvmLight (v4.2.30.23483) and in my PCL there are the MvvmLight Libraries for PCL (v4.2.30.16997), both up-to-date from Nuget. Do I need to downgrade a package to get the same build number, add the libraries manually or what can I do in order to make it work?

Thanks in advance!

You should reference the Portable.MvvmLightLibs NuGet package from both projects, and not any of the non-portable MvvmLight packages. The Portable.MvvmLightLibs package includes support for both PCLs and platform-specific libraries.

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