I'm following this tutorial on Screen
and ScreenConductors
in Caliburn.Micro
Framework.
I'm using WPF, not Silverlight, and I have made the corresponding changes in App.xaml (using MergedDictionary for the Bootstrapper).
The original Simple Navigation example has a shell with two buttons, and a content area where two possible screens are displayed, conducted by the ShellViewModel
.
Then I tried to move each button to its counterpart View, so that PageOne would have a button to take to PageTwo, and vice-versa. I did it because I don't want the home shell continuously "showing its entrails" across the application.
The fact is, if I just move a button to a Screen
View, it no longer binds to the command, which is in the ShellViewModel
, not in the Screen
ViewModel itself. I know these bindings happen by convention, but I don't know if the convention covers this case, or I'd need to configure.
The symptom I am facing is: When I run the app, PageOneView shows, with the "Go to Page Two" button in it, but when I click the button nothing happens.
The question I ask is: "How is the proper way to "bubble" a button in a ScreenView.xaml to an action in the ScreenConductorViewModel.cs?
My current code is below:
PageOneView.xaml
<UserControl x:Class="ScreenConductor.PageOneView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Background="LightGreen">
<Button x:Name="ShowPageTwo" Content="Show Page Two" HorizontalAlignment="Center" VerticalAlignment="Top" />
</Grid>
</UserControl>
PageOneViewModel
using Caliburn.Micro;
namespace ScreenConductor {
public class PageOneViewModel : Screen {
protected override void OnActivate() {
base.OnActivate();
}
}
}
ShellView.xaml
<Window x:Class="ScreenConductor.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<ContentControl x:Name="ActiveItem" />
</Window>
ShellViewModel.cs
using Caliburn.Micro;
namespace ScreenConductor
{
public class ShellViewModel : Conductor<object>
{
public ShellViewModel()
{
ShowPageOne();
}
public void ShowPageOne()
{
ActivateItem(new PageOneViewModel());
}
public void ShowPageTwo()
{
ActivateItem(new PageTwoViewModel());
}
}
}
http://caliburnproject.org
– Meissner