Add MvvmLight Template

This commit is contained in:
筱傑
2019-08-02 16:19:14 +08:00
committed by GitHub
parent 15b87f4685
commit ba24c4ea0f
13 changed files with 531 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
namespace MvvmLightDemo.ViewModel
{
public class MainViewModel : ViewModelBase
{
private string _Title;
public string Title
{
get => _Title;
set => Set(ref _Title, value);
}
public ICommand ChangeTitleCommand { get; set; }
public MainViewModel()
{
Title = "Hello World!";
ChangeTitleCommand = new RelayCommand(ChangeTitle);
}
private void ChangeTitle()
{
Title = "Hello MvvmLight!";
}
}
}

View File

@@ -0,0 +1,21 @@
using CommonServiceLocator;
using GalaSoft.MvvmLight.Ioc;
namespace MvvmLightDemo.ViewModel
{
public class ViewModelLocator
{
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<MainViewModel>();
}
public MainViewModel Main => ServiceLocator.Current.GetInstance<MainViewModel>();
public static void Cleanup()
{
// TODO Clear the ViewModels
}
}
}