做這樣的事情:如何將ViewModel應用於頁面內的UserControl?
<DataTemplate DataType="{x:Type vm:AllCustomersViewModel}">
<vw:AllCustomersView />
</DataTemplate>
作品在ResourceDictionary
時,我想一個ViewModel
應用於UserControl
爲根,但我怎麼同樣的事情時,我有一個UserControl
一個Page?``\ Would I create a
資源字典for all my Pages then at the top of each
內Page`這樣做:
<Page.Resources>
<ResourceDictionary Source="../MainWindowResources.xaml"/>
</Page.Resources>
是的,我有一個用戶控件,我想在一個頁面內。我問的是如何將ViewModel從App.xaml應用到頁面內部的UserControl?謝謝! – Mike 2010-02-28 20:16:43
在MVVM應用程序中,需要一些輔助方法來實現視圖和視圖模型之間的連接。我使用Mark Smith的圖書館:http://www.julmar.com/blog/mark/2009/08/04/MVVMHelpersV103.aspx。它定義了一個服務,該服務創建一個新窗口並將數據上下文正確設置爲視圖模型。 – Timores 2010-03-01 06:05:42