For a new project I want to try out the new .net core 3.0 WPF project and I want to use it in combination with MvvmLight. However in .net core and in combination with Visual Studio Code you don't get any scaffolding or default project. And then there is the mystery what to do to get it working...
I know I need to do something in app.xaml.cs, mainwindow.xaml and mainwindow.xaml.cs. As well as creating some ViewModelLocator service. But the documentation of MvvmLight is kinda empty on this.
I had found the following question on SO (MvvmLightLibsStd10 and UWP), but it isn't complete in my case and I am also unsure whether I should use the normal package or the special std10 version.
Update 2019-06-26 I got it to work with the following code, using MvvmLightLibsStd10 version 5.4.1.1.
App.xaml
<Application.Resources>
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="clr-namespace:$AssemblyName$.ViewModel" />
</ResourceDictionary>
</Application.Resources>
MainWindow.xaml
DataContext="{Binding ValidatorListViewModel, Source={StaticResource Locator}}">
ViewModelLocator.cs
using GalaSoft.MvvmLight.Ioc;
namespace $AssemblyName$.ViewModel
{
public class ViewModelLocator
{
public ViewModelLocator()
{
SimpleIoc.Default.Register<ValidatorListViewModel>();
}
public ValidatorListViewModel ValidatorListViewModel => SimpleIoc.Default.GetInstance<ValidatorListViewModel>();
}
}