前端绑定:DataContext="{Binding Source={StaticResource Locator},Path=ExamInfo}"项目下APP.xaml 配置
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Theme\Theme.xaml">
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:TDGTPTS.ViewModel" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
生成个容器类将做改变得类放进容器中调用
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<VM_PageExamInfo>();
生成方法
public VM_PageExamInfo ExamInfo
{
get
{
return ServiceLocator.Current.GetInstance<VM_PageExamInfo>();
}
}