Using VS2013 and Caliburn.Micro 2.0.2
Given this example of:
- a shell view model that has a nested view model property, and
- both the shell and nested view models having a
Name
property:
It seems that during design time the nested view model property is ignored. Is there a way to support this?
public class NestedViewModel : PropertyChangedBase
{
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
NotifyOfPropertyChange(() => Name);
}
}
public NestedViewModel()
{
Name = "Nested";
}
}
<UserControl
x:Class="WpfApplication1.Views.NestedView"
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"
xmlns:cal="http://www.caliburnproject.org"
xmlns:viewModels="clr-namespace:WpfApplication1.ViewModels"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:NestedViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True">
<Grid>
<Label x:Name="Name" FontSize="16" Background="LightGreen"/>
</Grid>
</UserControl>
The green label shows the correct Name
for the nested view model in the designer:
public class ShellViewModel : PropertyChangedBase
{
private string _name;
private NestedViewModel _nestedViewModel;
public string Name
{
get { return _name; }
set
{
_name = value;
NotifyOfPropertyChange(() => Name);
}
}
public NestedViewModel NestedViewModel
{
get { return _nestedViewModel; }
set
{
if (Equals(value, _nestedViewModel)) return;
_nestedViewModel = value;
NotifyOfPropertyChange(() => NestedViewModel);
}
}
public ShellViewModel()
{
NestedViewModel = new NestedViewModel();
Name = "Shell";
}
}
<UserControl
x:Class="WpfApplication1.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:viewModels="clr-namespace:WpfApplication1.ViewModels"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:ShellViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<ContentControl Grid.Row="0" x:Name="NestedViewModel"/>
<Label Grid.Row="1" x:Name="Name" FontSize="16" Background="RoyalBlue"/>
</Grid>
</UserControl>
The green label should show the nested view model Name
property in the designer, but instead shows the value of the shell view model:
It does bind correctly at runtime: