【发布时间】:2011-04-03 23:16:51
【问题描述】:
我创建了一个 MainView,它的 DataContext 是在 xaml 中初始化的 MainViewModel。
MainView 包含一个绑定到 MainViewModel 的 Content 属性的 ContentControl。
我在 MainViewModel 构造函数中添加了一些内容,这样如果当前用户没有登录,它会自动将 LoginView(以及相应的 DataContext LoginViewModel)加载到这个 Content 属性中。
现在我的问题是,当用户成功登录后我该怎么办:
'To be called from the LoginCommand
Private Sub Login
'Do Login
If WebContext.Current.User.IsAuthenticated Then
' - Publish a global event to be subscribed and caught from the MainViewModel
' - Close LoginView
' - The MainViewModel should set it's Content property back
' to what the user initially intended to open
End If
End Sub
这是怎么做到的?
注意:我更喜欢使用 prism 的 EventAggregator 而不是其他东西,但我不知道:
- 如何在 ViewModel 之间分散它
- 如何创建事件(我不需要传递参数,也不需要它是通用的,只需
Action、LoginAction- 无参数。 - 如何从 MainViewMode 订阅。
- 我不使用 MEF 或 Unity,也不使用单独的模块,我的所有应用程序都在一个程序集中。
- 我不希望在代码隐藏中编写任何代码
- 欢迎在 VB.NET 或 C# 中使用相同的答案
任何帮助都会被推荐
【问题讨论】:
标签: silverlight-4.0 mvvm navigation prism eventaggregator