I am created a MainView that it's DataContext is a MainViewModel initialized in xaml.
The MainView contains a ContentControl that is bound to the Content property of the MainViewModel.
I added some content in the MainViewModel constructor, so that if the current user is not logged in, it automatucally loads LoginView (and correspondingly it's DataContext LoginViewModel) into this Content property.
Now my question is, what should I do when the user successfully logs in:
'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
How is this done?
Note: I prefer using prism's EventAggregator
rathen then other stuff, but I have no clue:
- How to spread it out between the ViewModels
- How to create events (I don't need to pass parameter, nor do I need it to be generic, just
Action
,LoginAction
- no parameters. - How do I subscribe from the MainViewMode.
- I do NOT use MEF or Unity, nor do I use seperated modules, all my application is in one single assembly.
- I prefer not to write any code in the code-behind at all
- Answer in both VB.NET or C# are welcommed the same
Any help would be recommended