Reputation: 717
I am working on a WPF Application with Catel that has a Login Screen. How would I, after a user has entered his details and may proceed) close the Login Screen and display a 'Home' Screen using Catel?
I tried using the IUIVisualizerService, but I cannot pass it the user's name, for example, to be used within the viewmodel of the view that sits on the window to be opened, unless I am doing it wrong.
I have other scenarios in my application where I would need to open a new window from a currently opened one(I may require to close it before the new one is opened) and pass some data to the contained view's viewmodel.
Any suggestions?
SOME CODE AS REQUESTED:
/// <summary>
/// ViewModel for the Login Screen
/// </summary>
public class LoginWindowViewModel : ViewModelBase
{
public LoginWindowViewModel()
{
ShowHomeWindow = new Command(OnShowHomeWindowExecute);
}
public string Username { get; set; }
public override string Title { get { return "Login"; } }
public Command ShowHomeWindow { get; private set; }
private void OnShowHomeWindowExecute()
{
var viewModel = new HomeWindowViewModel();
var dependencyResolver = this.GetDependencyResolver();
var uiVisualizerService = dependencyResolver.Resolve<IUIVisualizerService>();
uiVisualizerService.Register(typeof(HomeWindowViewModel), typeof(HomeWindow));
uiVisualizerService.Show(viewModel, OnWindowClosed);
}
private void OnWindowClosed(object sender, EventArgs e)
{
}
}
/// <summary>
/// ViewModel for the Home Window
/// </summary>
public class HomeWindowViewModel : ViewModelBase
{
public HomeWindowViewModel()
{
}
}
/// <summary>
/// ViewModel for the Home View that sits in Home Window
/// </summary>
public class HomeViewModel : ViewModelBase
{
public HomeViewModel()
{
}
public string Username { get; set; }
}
So what needs to happen is that the Username from the LoginView's ViewModel (which is a UserControl on the LoginWindow) must get passed along to the Username on the HomeView's ViewModel (which is also a UserControl and sits on the HomeWindow).
This code is not important as this is a made up scenario. The core of what I am trying to figure out is how one would pass info along to other Windows' View's ViewModel when it is generated elsewhere.
Upvotes: 0
Views: 801
Reputation: 5724
See the getting started with WPF part of the docs. Normally there are services that manage selections / contain application-wide states. Then you let them be injected into your view models whenever you need them.
Upvotes: 1