2011-07-21 41 views
1

Caliburn.Micro是否支持設計時間數據? 我嘗試了以下步驟; 我創建了一個簡單的hello世界程序。 ShellViewModel從IShell派生而來。通過運行示例程序,它可以在運行時顯示問候語。由於視圖模型是從IShell衍生而來的,因此我創建了一個衍生自IShell的虛擬類,並將其用作設計時間實例。Caliburn.Micro是否支持設計時間數據?

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> 

認爲

有什麼我失蹤? 謝謝

+0

它。看起來完整,$ 10000的問題是,它是否適合你? –

+0

不,它不適用於我。 – Nair

+3

好吧你的d:DataContext =「等等...代碼是完美的你仍然需要Text = {綁定你好World}混合來訪問數據(Id完全隱藏在查看該部分),Blend不通過Caliburn約定活頁夾運行xaml。它需要明確設置。 –

回答

1

引用格雷姆的評論,因爲它回答了我的問題。

好你的d:DataContext="blah...代碼是完美的,你仍然需要Text={Binding HelloWorld}的混合訪問數據(ID完全掩蓋在看的那部分),混合不運行通過卡利約定粘結劑的XAML。它需要明確設置。

- 格雷姆·布拉德伯裏7月22日在15:14"

2

運用Bind.AtDesignTime應該做的伎倆

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