2010-10-03 69 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); 
}