我有一個UserControl UserControl1和UserControl1內的一個按鈕。我有一個UserControl1ViewModel,它具有該按鈕的ICommand屬性。使用這個命令,我需要從外部(從MainWindow的其他VM或VM)調用VM的方法。最佳做法是什麼?重新使用usercontrol內的控件
0
A
回答
0
你可能想通過洛朗比尼翁http://www.galasoft.ch/mvvm/getstarted/
這是幫助強制執行MVVM概念的輕量級工具來檢查MVVM精簡版。其中,每個viewmodel都是ViewModelLocator類中的靜態成員。例如,在你的命令中,你可以做這樣的事情。
ViewModelLocator.MainViewModel.MainContent = NewContent;
你完全可以做到這一點沒有MVVM精簡版,但使用它確實有助於加快學習曲線和執行模塊化。
0
你很可能希望實現Mediator模式來處理兩個viewmodels之間的通信。
沿着同樣的另一個SO問題是: mvvm-view-model-view-model-communications
0
我會考慮使用控制器ViewModels之間的中介。 The WPF Application Framework (WAF)顯示了這是如何工作的。
相關問題
- 1. UserControl內的Web控件null?
- 2. 訪問UserControl的內部控件
- 3. 如何訪問UserControl UserControl下的控件
- 4. 如何使我的控件在Winforms UserControl內部私有?
- 5. 如何使我的控件在UserControl私人內部?
- 6. WPF UserControl不更新內容
- 7. 可以重新使用WPF控件嗎?
- 8. 重新使用Web瀏覽器控件
- 9. 使用UpdatePanel控件只刷新內容
- 10. TextBox MouseDown UserControl內的事件
- 11. 使用usercontrol頁面調用App_code文件夾內的Class文件?
- 12. 如何從相同的用戶控件找到usercontrol的控件
- 13. UserControl的OnRepaint事件後,控件從父UserControl中消失
- 14. 在另一個用戶控件內部訪問UserControl
- 15. FlowLayoutPanel裏面的UserControl內部的控件的處理值改變
- 16. WPF UserControl填充控件
- 17. 如何防止UserControl的使用者看到控件的子控件?
- 18. 在多個用戶控件中使用Usercontrol的單個實例
- 19. 用另一個控件隱藏UserControl中的子控件
- 20. 如何使用UserControl內的TwoWay綁定?
- 21. 使用System.Windows.Forms.Timer控件更新標籤期間的內存使用
- 22. 用戶控件Storyboard對象移出UserControl
- 23. 重新評估UserControl中的屬性
- 24. 重新使用控制器內的ActionResult代碼
- 25. 使用新的PDF文件重新加載對象的內容
- 26. 在另一個用戶控件中的控件中更新usercontrol中的更新面板
- 27. UserControl with Dependancy Properties取代類似控件的重複設置
- 28. 如何在Designer中隱藏UserControl的內部控件?
- 29. 通過COM使用.NET的UserControl作爲嵌入式控件
- 30. 使用XAML將控件添加到UserControl中的ItemsControl中
我瞭解中介模式。但我很困惑我將如何允許外部處理程序的命令。 – Lance 2010-04-08 10:20:01