首页 新闻 会员 周边 捐助

MVVMLight框架问题

0
悬赏园豆:10 [待解决问题]

 ViewModelLocator类不太理解

ViewModelLocator 是连接view 和viewmodel用的。我疑惑的系统所有的viewmodel都要在这个类注册一遍吗?比如我500个viewmodel ,那我就写500行注册的代码?(如:SimpleIoc.Default.Register<TestViewModel>();)

这样写一次行加载完,这样写的性能会不会不好,内存会不会增加很多?

public class ViewModelLocator
{
static ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

if (ViewModelBase.IsInDesignModeStatic)
{
SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
}
else
{
SimpleIoc.Default.Register<IDataService, DataService>();
}

SimpleIoc.Default.Register<MainViewModel>();
SimpleIoc.Default.Register<TestViewModel>();
}

/// <summary>
/// Gets the Main property.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}

public TestViewModel Test
{
get
{
return ServiceLocator.Current.GetInstance<TestViewModel>();
}
}
/// <summary>
/// Cleans up all the resources.
/// </summary>
public static void Cleanup()
{
}
}

夜星冷的主页 夜星冷 | 初学一级 | 园豆:71
提问于:2016-03-08 17:28
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册