When starting the application I'd like to open by default a user control, but only the empty shell view displayed.
Following the usual Caliburn pattern and using SimpleContainer in the ShellViewModel constructor everything is executed fine, but can't see the activated vm.
The ShellViewModel
public class ShellViewModel : Conductor<object>, IHandle<NewLayoutCreatedEvent>
{
private readonly SimpleContainer _container;
private readonly IEventAggregator _events;
private readonly IWindowManager _manager;
public ShellViewModel(IEventAggregator events, IWindowManager manager, SimpleContainer container)
{
_events = events;
_events.Subscribe(this);
_manager = manager;
_container = container;
ActivateItem(_container.GetInstance<WorkLayoutViewModel>());
}
}
The WorkLayoutViewModel is inheriting from Screen. In the Bootstrapper class what happens is after running the constructor of WorkLayoutViewModel:
protected override object GetInstance(Type service, string key)
{
return _container.GetInstance(service, key);
}
called once with null key and service = ShellViewModel then continue with:
protected override IEnumerable<object> GetAllInstances(Type service)
{
return _container.GetAllInstances(service);
}
where service again ShellViewModel, which runs the InitializeComponent() in the ShellView class. After this jumping to:
protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<ShellViewModel>();
}
where the sender is the app itself and no args. Following this the App class OnStartup() override called where I'm setting up language and calling base.OnStartup()
I believe the GetAllInstances should call the WorkLayoutViewModel too not just the ShellViewModel, this is not happening and the view is not displayed.
As requested the ShellView:
<Window x:Class="MyApp.Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MyApp.Views"
xmlns:lang="clr-namespace:MyApp.Language;assembly=MyApp.Language"
xmlns:interact="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
Title="{x:Static lang:Resources.AppName}" Height="800" Width="1000" WindowStartupLocation="CenterScreen">
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<Menu FontSize="14" Height="27">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel HorizontalAlignment="Stretch" />
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Header="{x:Static lang:Resources.Mnu_File}" HorizontalAlignment="Left">
<MenuItem Header="{x:Static lang:Resources.Mnu_New}">
<MenuItem.Icon>
<Image Source="/Images/new.png" />
</MenuItem.Icon>
<interact:Interaction.Triggers>
<interact:EventTrigger EventName="Click">
<cal:ActionMessage MethodName="NewLayout"/>
</interact:EventTrigger>
</interact:Interaction.Triggers>
</MenuItem>
</MenuItem>
</Menu>
<ToolBar Height="36">
<Button ToolTip="{x:Static lang:Resources.Tip_New}">
<Image Source="/Images/new.png" />
<interact:Interaction.Triggers>
<interact:EventTrigger EventName="Click">
<cal:ActionMessage MethodName="NewLayout"/>
</interact:EventTrigger>
</interact:Interaction.Triggers>
</Button>
</ToolBar>
</StackPanel>
<Grid>
<ContentControl x:Name="ActivateItem" Margin="10 5 10 10" />
</Grid>
</DockPanel>
</Window>
and the WorkLayoutView is just a standard UserControl with red back ground.