I have a main window which hosts two views (user controls). One is UserControl1 and the other is UserControl2 following a toggle system.
UserControl1 loads first and then the view can be toggled. I wish to launch a window after UserControl1 is loaded.
I am launching views using the messaging pattern and registering the views in app.xaml or MainView.xaml.
How should I proceed?
Xaml for my MainView:
<Window x:Class="CustomListView.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:CustomView="clr-namespace:CustomListView"
Title="MainView"
Width="300"
Height="300">
<Window.InputBindings>
<CustomView:RelayKeyBinding Key="F12" CommandBinding="{Binding Path=Toggle}"></CustomView:RelayKeyBinding>
</Window.InputBindings>
<Window.Resources>
<DataTemplate x:Key="ExecutionView">
<CustomView:ExecutionView />
</DataTemplate>
<DataTemplate x:Key="ConfigView">
<CustomView:ConfigView />
</DataTemplate>
<Style x:Key="mainContentControlStyle"
TargetType="{x:Type ContentControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Mode}"
Value="1">
<Setter Property="ContentTemplate" Value="{StaticResource ResourceKey=ConfigView}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Mode}"
Value="0">
<Setter Property="ContentTemplate" Value="{StaticResource ResourceKey=ExecutionView}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<ContentControl Content="{Binding}"
Style="{StaticResource ResourceKey=mainContentControlStyle}" />
</Grid>
</Window>
If you require any more code I’ll be happy to post it.
Thanks in advance.
You could use an EventTrigger to convert the Loaded event of the Window into a command execution, then create your window there. This would be my code:
If you are using MVVM Light, this is the code: