1

Caliburn.Micro 是否支持设计时数据?我尝试了以下步骤;我创建了一个简单的 hello world 程序。ShellViewModel 是从 IShell 派生的。通过运行示例程序,它会在运行时显示 hello word。由于视图模型是从 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>

有什么我想念的吗?谢谢

4

3 回答 3

4

请查看Caliburn Micro 设计数据示例。通过德里克比蒂。

于 2012-03-24T22:34:53.210 回答
2

应用 Bind.AtDesignTime 应该可以解决问题。

<UserControl 
     xmlns:cal="http://www.caliburnproject.org"
     cal:Bind.AtDesignTime="True"
     >
    <!-- etc -->
</UserControl>
于 2013-12-15T09:59:42.407 回答
1

引用 Graeme 的评论,因为它回答了我的问题。

好的,您的d:DataContext="blah...代码很完美,您仍然需要Text={Binding HelloWorld}混合来访问数据(Id 完全掩盖了查看该部分的内容),Blend 不会通过 Caliburn 约定活页夹运行 xaml。它需要明确设置。

– Graeme Bradbury 7 月 22 日 15:14"

于 2011-08-17T13:56:49.020 回答