Note that there are some explanatory texts on larger screens.

plurals
  1. POLaunch a View(Window) after UserControl is Loaded in WPF using MVVM
    primarykey
    data
    text
    <p>I have a main window which hosts two views (user controls). One is <code>UserControl1</code> and the other is <code>UserControl2</code> following a toggle system. </p> <p><code>UserControl1</code> loads first and then the view can be toggled. I wish to launch a window after <code>UserControl1</code> is loaded.</p> <p>I am launching views using the messaging pattern and registering the views in <code>app.xaml</code> or <code>MainView.xaml</code>.</p> <p>How should I proceed?</p> <p><strong>Xaml for my MainView:</strong></p> <pre><code> &lt;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"&gt; &lt;Window.InputBindings&gt; &lt;CustomView:RelayKeyBinding Key="F12" CommandBinding="{Binding Path=Toggle}"&gt;&lt;/CustomView:RelayKeyBinding&gt; &lt;/Window.InputBindings&gt; &lt;Window.Resources&gt; &lt;DataTemplate x:Key="ExecutionView"&gt; &lt;CustomView:ExecutionView /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="ConfigView"&gt; &lt;CustomView:ConfigView /&gt; &lt;/DataTemplate&gt; &lt;Style x:Key="mainContentControlStyle" TargetType="{x:Type ContentControl}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Path=Mode}" Value="1"&gt; &lt;Setter Property="ContentTemplate" Value="{StaticResource ResourceKey=ConfigView}" /&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Binding="{Binding Path=Mode}" Value="0"&gt; &lt;Setter Property="ContentTemplate" Value="{StaticResource ResourceKey=ExecutionView}" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;ContentControl Content="{Binding}" Style="{StaticResource ResourceKey=mainContentControlStyle}" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>If you require any more code I'll be happy to post it.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload