如何将DesignInstance与Caliburn.Micro一起使用

时间:2012-02-02 05:34:01

标签: c# wpf caliburn.micro lookless

我正在使用Caliburn.Micro

我有这个WPF视图,在设计时,在诸如firstname等基本属性上成功使用样本数据但是不能找到属性和复杂类型集合的视图

<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";
    }
}

1 个答案:

答案 0 :(得分: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">
相关问题