2010-10-03 67 views
10

我想学习MVVM光,我正在寻找一个很好的基本示例,显示一个模型以及如何加载不同的视图。寻找简单的MVVM光的例子

我在下载MVVM Light后看到的模板没有模型,只有一个视图。 (http://www.galasoft.ch/mvvm/creating/)

我发现的其他事情更复杂,有点令人困惑,当我想看到的是基本知识。

谢谢。

回答

8

我发现这个例子帮助:

http://apuntanotas.codeplex.com/

+1

这个e中的“模型” xample实现INotify。我倾向于将模型视为使用POCO(Plain Old CLR对象)并使用实现INotify的ModelView来允许数据绑定。 – 2016-02-26 16:35:42

1

我个人认为这是一个非常有用的,虽然他们也使用MEF和RIA服务可以使事情变得复杂:

A Sample Silverlight 4 Application Using MEF, MVVM, and WCF RIA Services

Architecting Silverlight 4 with RIA Services MEF and MVVM - Part 1

四月,MVVM光的作者工具包说他最终会在Silverlight和WPF中创建一个参考应用程序。 (Source)

您可能会发现这些有用的其他问题:我发现这两个

mvvm light toolkit samples

wpf/silverlight mvvm sample app request

mvvm tutorial from start to finish

1

是非常有帮助的:

http://www.codeproject.com/KB/WPF/blendable_locator.aspx http://rickrat.wordpress.com/2011/01/24/using-mef-to-link-view-model-locator-and-load-assembly-uis-dynamically

first其中一个只是MVVM Light的简单插入式viewModelLocator类,它为您提供了MEF的功能。

[ExportViewModel("Demo1", false)] 
class Demo1ViewModel : ViewModel 
{ 
} 

而且second一个,使用与打开运行MEF部件的时间装载额外MefHelper类相同的方法。

public void Compose() 
{ 
AggregateCatalog Catalog = new AggregateCatalog(); 
// Add This assembly's catalog parts 
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly(); 
Catalog.Catalogs.Add(new AssemblyCatalog(ass)); 

// Directory of catalog parts 
if (System.IO.Directory.Exists(ExtensionsPath)) 
{ 
    Catalog.Catalogs.Add(new DirectoryCatalog(ExtensionsPath)); 
    string[] folders = System.IO.Directory.GetDirectories(ExtensionsPath); 

    foreach (string folder in folders) 
    { 
     Catalog.Catalogs.Add(new DirectoryCatalog(folder)); 
    } 

} 

_Container = new CompositionContainer(Catalog); 
}