0
我在我的項目中使用MVVM,這是我的問題。我有一個視圖和相應的帶有服務引用的視圖模型。該視圖包含UserControl,它具有另一個UserControl,並且它也包含嵌套的UserControl。 Last UserControl有一個創建彈出窗口的方法。在這個彈出窗口中,我需要查看模型的服務參考。每個用戶控件都有自己的DataContext。PRISM UserControl和ServiceReference
代碼解釋。
查看XAML:
<UserControl DataContext="{Binding ViewModel}">
<FunctionsList/>
</UserControl>
FunctionsList XAML:
<UserControl>
<Function1/>
<Function2/>
<Function3/>
<Function4/>
</UserControl>
功能3 XAML:
<UserControl/>
功能3後面的代碼包含CreatePopup方法,其與UserControl
Function3Popup作爲創建對話內容。而Function3Popup應該有Service引用。
這裏的最佳做法是什麼?我有一個可怕的解決方案來使用綁定來傳遞引用,但對我來說似乎讓人灰心。