mirror of
https://github.com/jie65535/Helpers.git
synced 2025-10-16 17:29:45 +08:00
Add MvvmLight Template
This commit is contained in:
31
MvvmLightDemo/ViewModel/MainViewModel.cs
Normal file
31
MvvmLightDemo/ViewModel/MainViewModel.cs
Normal 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!";
|
||||
}
|
||||
}
|
||||
}
|
21
MvvmLightDemo/ViewModel/ViewModelLocator.cs
Normal file
21
MvvmLightDemo/ViewModel/ViewModelLocator.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user