2012-02-02 74 views
3

我使用Caliburn.Micro如何使用DesignInstance与Caliburn.Micro

我有这个WPF认为,在设计时采用的样本数据成功地在诸如姓名等基本属性,但不能将找不到视图对于复杂类型

<UserControl x:Class="NonRepositoryItems.Reviewer.ReviewerView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:Controls="clr-namespace:MyFramework.Controls.BusyIndicator.Implementation;assembly=App.Framework" 
     xmlns:cal="http://www.caliburnproject.org" 
     xmlns:FormPanel="clr-namespace:MyFramework.Controls.FormPanel;assembly=App.Framework" 
     xmlns:SampleData="clr-namespace:NonRepositoryItems.SampleData" 
     mc:Ignorable="d" 
     d:DataContext="{d:DesignInstance SampleData:SampleReviewerViewModel, IsDesignTimeCreatable=True}" 
     > 
<Grid> 
    <Border> 
     <DockPanel> 
      <DockPanel.Resources> 
       <Style TargetType="Label" > 
        <Setter Property="FontWeight" Value="Bold" /> 
        <Setter Property="FontSize" Value="12" /> 
       </Style> 
       <Style TargetType="TextBlock" > 
        <Setter Property="VerticalAlignment" Value="Center" /> 
       </Style> 
      </DockPanel.Resources> 
      <FormPanel:FormPanel Columns="2" Margin="5" DockPanel.Dock="Top"> 
       <Label Content="Job Title"/> 
       <TextBlock Text="{Binding JobTitle}" /> 

       <Label Content="Honorific"/> 
       <TextBlock Text="{Binding Honorific}" /> 

       <Label Content="First Name"/> 
       <TextBlock Text="{Binding FirstName}" /> 

       <Label Content="Last Name"/> 
       <TextBlock Text="{Binding LastName}" /> 

       <Label Content="Gender"/> 
       <TextBlock Text="{Binding Gender}" /> 

      </FormPanel:FormPanel> 

      <FormPanel:FormPanel Columns="1" Margin="5" DockPanel.Dock="Top"> 
       <Label Content="Postal Address"/>      
       <ContentControl cal:View.Model="{Binding PostalAddress}" />   
       <Label Content="Courier Address"/> 
       <ContentControl cal:View.Model="{Binding CourierAddress}" /> 
      </FormPanel:FormPanel> 
      <ListView ItemsSource="{Binding RepositoryItems}"></ListView> 
     </DockPanel> 

    </Border> 

    <Controls:BusyIndicator IsBusy="{Binding IsBusy}" BusyContent="Busy..." Grid.ColumnSpan="2"></Controls:BusyIndicator> 
    <ContentControl x:Name="Dialogs" 
        VerticalContentAlignment="Stretch" 
        HorizontalContentAlignment="Stretch"/> 
</Grid> 
</UserControl> 

这里的属性和集合,是的sampleData

public class SampleReviewerViewModel : ReviewerViewModel 
{ 
    public SampleReviewerViewModel() 
    { 
     Honorific = "Mr"; 
     FirstName = "John"; 
     LastName = "Smith"; 
     ReviewerId = "125634"; 
     Gender = "Male"; 
     JobTitle = "REC Chair"; 
     ReviewerTaskCount = "10"; 
     ReviewerRequestedTaskCount = "20"; 
     ReviewerDispatchedTaskCount = "33"; 
     ReviewerRequestedReturnedCount = "50"; 
     PostalAddress = new AddressViewModel(); 
     CourierAddress = new AddressViewModel(); 
     IsBusy = false; 
     RepositoryItems = new ObservableCollection<RepositoryItemViewModel> 
         { 
          new RepositoryItemViewModel() {Title = "Red"  }, 
          new RepositoryItemViewModel() {Title = "Orange" }, 
          new RepositoryItemViewModel() {Title = "Yellow" }, 
          new RepositoryItemViewModel() {Title = "Green" }, 
          new RepositoryItemViewModel() {Title = "Blue"  }, 
          new RepositoryItemViewModel() {Title = "Indigo" }, 
          new RepositoryItemViewModel() {Title = "Violet" } 
         }; 
    } 

} 

这是我的地址查看

<UserControl x:Class="NonRepositoryItems.Reviewer.AddressView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    
     xmlns:SampleData="clr-namespace:NonRepositoryItems.SampleData" mc:Ignorable="d" 
      d:DataContext="{d:DesignInstance SampleData:SampleAddressViewModel, IsDesignTimeCreatable=True}" 
     > 

<Border> 
<Grid Margin="4"> 
    <StackPanel> 
      <TextBlock Text="{Binding AddressLine1}" Visibility="{Binding IsAddressLine1Visible, Converter={StaticResource booleanToVisibility}}"/> 
      <TextBlock Text="{Binding AddressLine2}" Visibility="{Binding IsAddressLine2Visible, Converter={StaticResource booleanToVisibility}}" /> 
      <TextBlock Text="{Binding AddressLine3}" Visibility="{Binding IsAddressLine3Visible, Converter={StaticResource booleanToVisibility}}" /> 
      <TextBlock Text="{Binding City}"   Visibility="{Binding IsCityVisible, Converter={StaticResource booleanToVisibility}}"/> 
      <TextBlock Text="{Binding PostCode}"  Visibility="{Binding IsPostCodeVisible, Converter={StaticResource booleanToVisibility}}"/> 
      <TextBlock Text="{Binding Country}"  Visibility="{Binding IsCountryVisible, Converter={StaticResource booleanToVisibility}}"/> 
    </StackPanel> 
</Grid> 
</Border> 
</UserControl> 

,它的样本数据

public class SampleAddressViewModel : AddressViewModel 
{ 

    public SampleAddressViewModel() 
    { 
     Type = "Mail Address"; 
     AddressLine1 = "350 Fifth Avenue"; 
     AddressLine2 = ""; 
     AddressLine3 = ""; 
     City = "New York, NY "; 
     PostCode = "10118"; 
     Country = "United States of America"; 
    } 
} 

回答

6

难道你需要在你的用户控件cal:Bind.AtDesignTime="True"

<UserControl x:Class="NonRepositoryItems.Reviewer.AddressView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    
     xmlns:SampleData="clr-namespace:NonRepositoryItems.SampleData" mc:Ignorable="d" 
      d:DataContext="{d:DesignInstance SampleData:SampleAddressViewModel, IsDesignTimeCreatable=True}" 
     cal:Bind.AtDesignTime="True"> 
+0

我没有那个属性。 cal:绑定中只有一个Model属性。我应该使用另一个程序集吗?这篇文章似乎是我所追求的,但是如果我有兴趣了解更多的综合方法,请参阅http://mnajder.blogspot.com.au/2011/09/design-time-support-for-caliburnmicro .html – Peter 2012-02-02 23:27:07

+1

你在哪个版本的CM上?该博客文章中的内容现在已内置。这是一个SL示例:https://bitbucket.org/dbeattie/designdata/src – 2012-02-03 00:41:23

+0

我使用的是通过NuGet v 1.2.0来的那个 – Peter 2012-02-03 01:08:44

相关问题