Search code examples
visual-studio-2010silverlightxamlmvvmdevforce

Issue with XAML Design data for ItemsControl


I'm trying to master design data for VS2010 (not Blend) in my MVVM project.

I got it working for top-level VM properties, but have problem with collections. I use DevForce for data modeling, so ideally my XAML should look like this:

<MaintainTruckViewModel 
    xmlns="clr-namespace:IDATT.Module.Assets.Views"
    xmlns:data="clr-namespace:IDATT.Model;assembly=IDATT.Model.SL">
    <MaintainTruckViewModel.CurrentItem>
        <data:ASTTruck
            TruckId="1000"
            ExternalTruckId="T1000"
            IsActive="True"
            VinNumber="1ZAXBV"
            Make="Volvo"
            Model="ABC"
            MakeYear="2010"
            PlateNumber="ABC 123"
            PlateIssueAdministrativeArea="MO"
            Height="110"
            AxlesCount="3">
            <data:ASTTruck.ASTInsurances>
                <data:ASTInsurance
                    InsuranceKey="1"
                    CompanyName="MainCo"
                    AgentCompanyName="Joes insurance"
                    CoverageAmount = "1000000"
                    DeductibleAmount = "1000"
                    InsuranceType = "General liability"
                    IsActive = "True"
                    PolicyNumber = "123ABC"
                    ExpireOn = "01-01-2012"
                    Note = "This insurance covers all stuff"/>
            </data:ASTTruck.ASTInsurances>
        </data:ASTTruck>
    </MaintainTruckViewModel.CurrentItem>
</MaintainTruckViewModel> 

My xaml look like this and I expect to see ASTInsurance data in design view but it doesn't show up

<ItemsControl 
                    Grid.Row="1"
                    ItemsSource="{Binding CurrentItem.ASTInsurances}">

I don't know how to make various lists to "work" from design data. Any pointers? I found somewhere that I can use separate d:DesignData for list and tried to create such XAML:

<Generic:List 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:Generic="clr-namespace:System.Collections.Generic;assembly=mscorlib"
    x:TypeArguments="data:ASTInsurance" 
    xmlns:data="clr-namespace:IDATT.Model;assembly=IDATT.Model.SL">
                <data:ASTInsurance
                    InsuranceKey="1"
                    CompanyName="Great West"
                    AgentCompanyName="Joes insurance"
                    CoverageAmount = "1000000"
                    DeductibleAmount = "1000"
                    InsuranceType = "General liability"
                    IsActive = "True"
                    PolicyNumber = "123ABC"
                    ExpireOn = "01-01-2012"
                    Note = "This insurance covers all stuff"/>

</Generic:List> 

Now XAML editor underlines Generic.List and says The type 'Generic:List' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built


Solution

  • The problem with attempting to use System.Collections.Generic.List<T> in XAML is that (as far as I know) the Silverlight dialect of XAML contains no way to specify values for generic type parameters. The error you're getting is because there is no type System.Collections.Generic.List that does not have a type parameter.

    One thing you can do is to create a subclass of List<T> that supplies a value for the type parameter but contains no new nor overridden members, for example:

    public class ASTInsuranceList : List<ASTInsurance>
    {
    }
    

    You can then use an ASTInsuranceList object in XAML to contain a list of ASTInsurance objects.