Caliburn.Micro 支持设计时数据吗?

发布于 2024-11-25 17:38:29 字数 1237 浏览 9 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆光飞翔i 2024-12-02 17:38:29

请查看 Caliburn Micro 设计数据示例,作者:Derek Beattie。

Please, look at Example of Caliburn Micro design data. by Derek Beattie.

云淡月浅 2024-12-02 17:38:29

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

<UserControl 
     xmlns:cal="http://www.caliburnproject.org"
     cal:Bind.AtDesignTime="True"
     >
    <!-- etc -->
</UserControl>

Applying the Bind.AtDesignTime should do the trick.

<UserControl 
     xmlns:cal="http://www.caliburnproject.org"
     cal:Bind.AtDesignTime="True"
     >
    <!-- etc -->
</UserControl>
ぇ气 2024-12-02 17:38:29

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

好吧,您的 d:DataContext="blah... 代码非常完美,您仍然需要 Text={Binding HelloWorld} 来混合访问数据(Id 完全被掩盖)看看那部分),Blend 不通过 Caliburn 约定绑定程序运行 xaml,它需要显式设置。

– Graeme Bradbury,7 月 22 日 15:14”。

Quoting Graeme's comment, since it answered my question.

Okay your d:DataContext="blah... code is perfect you still need Text={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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文