3

I am using Caliburn.Micro

I have this WPF View that in design time uses sample data successfully on basic properties like firstname etc but can't won't find the view for properties and collections of complex types

<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>

Here is the 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"   }
                        };
    }

}

Here is my address view

<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>

and it's sample data

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";
    }
}
superjos
  • 12,189
  • 6
  • 89
  • 134
Peter
  • 7,792
  • 9
  • 63
  • 94

1 Answers1

6

Don't you need cal:Bind.AtDesignTime="True" on your user control.

<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">
Derek Beattie
  • 9,429
  • 4
  • 30
  • 44
  • I don't have that property. cal:Bind only have a Model property in it. Is there another assembly I should be using. This article seems to be what I'm after but if there is a more integrated way I'd be interested to know http://mnajder.blogspot.com.au/2011/09/design-time-support-for-caliburnmicro.html – Peter Feb 02 '12 at 23:27
  • 1
    What version of CM are you on? The stuff from that blog post is built in now. Here's a SL example: https://bitbucket.org/dbeattie/designdata/src – Derek Beattie Feb 03 '12 at 00:41
  • I'm using the one that comes through NuGet v 1.2.0 – Peter Feb 03 '12 at 01:08
  • That is weird because I used the Manage Nuget Packages thing to get mine...but when I Install-Package Caliburn.Micro it downloads the latest – Peter Feb 03 '12 at 02:15