Caliburn.Micro 支持设计时数据吗?
Caliburn.Micro 支持设计时数据吗? 我尝试了以下步骤; 我创建了一个简单的 hello world 程序。其中 ShellViewModel 派生自 IShell。通过运行示例程序,它确实在运行时显示 hello 词。由于视图模型是从 IShell 派生的,因此我创建了一个也从 IShell 派生的虚拟类,并将其用作设计时实例。
public class SampleShellViewModel:IShell
{
#region IShell Members
public string HelloWorld
{
get { return "Hello World"; }
}
#endregion
}
在视图中,我添加了设计时上下文,如下所示,
<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>
我缺少什么吗? 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请查看 Caliburn Micro 设计数据示例,作者:Derek Beattie。
Please, look at Example of Caliburn Micro design data. by Derek Beattie.
应用 Bind.AtDesignTime 应该可以解决问题。
Applying the Bind.AtDesignTime should do the trick.
引用格雷姆的评论,因为它回答了我的问题。
– Graeme Bradbury,7 月 22 日 15:14”。
Quoting Graeme's comment, since it answered my question.
– Graeme Bradbury Jul 22 at 15:14"