Does Caliburn.Micro support design time data?
Does Caliburn.Micro support design time data? I tried out with following steps; I created a simple hello开发者_运维技巧 world program. Where ShellViewModel is derived off of IShell. By running the sample program it does show hello word at run time. Since the view model is derived off of IShell I created a dummy class also derived off of IShell and used it as the design time instance.
public class SampleShellViewModel:IShell
{
#region IShell Members
public string HelloWorld
{
get { return "Hello World"; }
}
#endregion
}
in the view I added the design time context as follows
<UserControl x:Class="HelloWorld.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"
mc:Ignorable="d"
xmlns:sampleData="clr-namespace:HelloWorld"
d:DesignHeight="287" d:DesignWidth="518"
>
<Grid Background="White" d:DataContext="{d:DesignInstance sampleData:SampleShellViewModel, IsDesignTimeCreatable=True}">
<TextBlock Name="HelloWorld"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="20" />
</Grid>
Is there anything I a missing? Thanks
Please, look at Example of Caliburn Micro design data. by Derek Beattie.
Applying the Bind.AtDesignTime should do the trick.
<UserControl
xmlns:cal="http://www.caliburnproject.org"
cal:Bind.AtDesignTime="True"
>
<!-- etc -->
</UserControl>
Quoting Graeme's comment, since it answered my question.
Okay your
d:DataContext="blah...
code is perfect you still needText={Binding HelloWorld}
for blend to access the data (Id completely glossed over looking at that part), Blend doesn't run the xaml through the Caliburn convention binder. It needs to be explicitly set.
– Graeme Bradbury Jul 22 at 15:14"
精彩评论