In MVVM fashion, I have an initial window opening (MainView) with its DataContext (i.e., its viewmodel) being initialized from the code-behind:
XAML:
<Window x:Class="Nova5.UI.Views.MainView" ..............
Code-Behind C#:
public partial class MainView : Window
{
private MainViewModel vm = new MainViewModel(new WPFMessageBoxService());
public MainView()
{
InitializeComponent();
this.Loaded += (s, e) => { this.DataContext = this.vm; };
}
}
From there on out, I use a DialogService to open other windows from UserControls:
XAML:
<Window x:Class="Nova5.UI.Views.WindowDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowDialog"
WindowStyle="SingleBorderWindow"
WindowStartupLocation="Manual" SizeToContent="WidthAndHeight">
<ContentPresenter x:Name="DialogPresenter" Content="{Binding .}"/>
</Window>
The ViewModel creates the WindowDialog and associated viewmodel and opens the window.
All is good.
Now the problem. Lets say I have ten usercontrols. Each of these UserControls can be presented by the DialogService. Each of these UserControls can open other UserControls.
What I would like to do is have the MainWindow open UserControl_1. Then have UserControl_1 open UserControl_2. UserControl_1 then needs to close leaving UserControl_2 open. Ofcourse, UserControl_2 can open UserControl_3 after which UserControl_2 disappears leaving only the MainWindow and UserControl_3. In short, each launched UserControl needs to be independent of the control that created it.
I hope this is understandable.
How can this be done? Thanks for any ideas or help.