# MvvmLight
**Repository Path**: neoj/mvvm-light
## Basic Information
- **Project Name**: MvvmLight
- **Description**: mvvm-light
- **Primary Language**: C#
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2022-10-27
- **Last Updated**: 2023-04-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# MvvmLight
#### 使用说明
1.引用GalaSoft.MvvmLight.dll
2.App.xaml修改
3.添加ViewModels目录下ViewModelLocator.cs
using GalaSoft.MvvmLight.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace TemplateWPF.ViewModel
{
public class ViewModelLocator
{
public ViewModelLocator()
{
RegisterVM();
}
#region Register_VM
public void RegisterVM()
{
SimpleIoc.Default.Register();
}
#endregion
///
/// 反射获取ViewModelLocator的实例
///
public static ViewModelLocator Instance => new Lazy(() =>
Application.Current.TryFindResource("Locator") as ViewModelLocator).Value;
///
/// 删除实例并重新注册
///
///
public static void CloseVM() where T : class
{
if (SimpleIoc.Default.ContainsCreated())
{
SimpleIoc.Default.Unregister();
SimpleIoc.Default.Register();
}
}
#region GetInstance_Vm
public MainViewModel Main => SimpleIoc.Default.GetInstance();
#endregion
}
}
4.MainViewModel修改
4.1
public class MainViewModel : ViewModelBase
4.2 属性通知
private UserInfo userNow;
///
/// 当前用户
///
public UserInfo UserNow
{
get
{
return userNow;
}
set
{
userNow = value;
RaisePropertyChanged();
}
}
4.3 命令
///
/// 关闭窗口
///
public RelayCommand ExitCmd => new RelayCommand(() =>
{
UIExecute.RunAsync(() =>
{
Application.Current.Shutdown();
});
});
#region 初始化
public RelayCommand