简体   繁体   中英

.NET Framework 4.7 to .NET 5 Migration with Galasoft MVVMLight Library

We are migrating our WPF application to .NET 5.

Today we faced some problems with Galasoft Library named MVVMLight . We saw that there are no updates for .NET Standard. We cannot use ae EventToCommand class.

Do you know which options could we manage?

The regular MVVMLight and MVVMLightLibs NuGet packages are incompatible with .NET 5, they are only compatible with .NET Framwork and a few other platforms. However, there are dedicated packages for .NET Standard 1.0 which will work for .NET 5, too.

You can read more about these versions on the offical MVVMLight web page here . Please be aware, that this version does not support the IServiceProvider interface.

One particular interface, IServiceProvider, which is used by the SimpleIoc component, is not available in .NET Standard 1.0. [...] the ServiceLocator class is not available anymore.

This affects SimpleIoC, which you have to get through the static SimpleIoc.Default member instead.

// OLD var nav = ServiceLocator.Current.GetInstance<INavigationService>();
// NEW
var nav = SimpleIoc.Default.GetInstance<INavigationService>();

An alternative is to use the the XamlBehaviors for WPF if you are searching for a repacement for EventToCommand . This is a library by Microsoft that replaces the legacy Blend behaviors.

You can install the NuGet package Microsoft.Xaml.Behaviors.Wpf , which is compatible with .NET Framework, .NET Core and .NET 5. The equivalent to EventToCommand there is InvokeCommandAction .

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