1 按照《prism项目搭建》搭建prism项目
2 修改MainWindow.xaml,使其自动连接ViewModel,并将Title绑定到Title属性
prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}"
3 在主项目中添加ViewModels文件夹,并在其下面添加MainWindowViewModel类
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prism.ViewModelLocator.ViewModels
{
public class MainWindowViewModel:BindableBase
{
private string _Title = "Hello";
public string Title
{
get { return _Title; }
set { SetProperty(ref _Title, value); }
}
}
}
4 项目结构如下