【问题标题】:Issue with XAML Design data for ItemsControlItemsControl 的 XAML 设计数据问题
【发布时间】:2012-12-18 04:46:24
【问题描述】:

我正在尝试在我的 MVVM 项目中掌握 VS2010(不是 Blend)的设计数据。

我让它适用于顶级 VM 属性,但集合有问题。我使用 DevForce 进行数据建模,所以理想情况下我的 XAML 应该如下所示:

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

我的 xaml 看起来像这样,我希望在设计视图中看到 ASTInsurance 数据,但它没有显示

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

我不知道如何根据设计数据制作各种“工作”列表。任何指针?我发现某个地方可以使用单独的 d:DesignData 作为列表并尝试创建这样的 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> 

现在 XAML 编辑器在 Generic.List 下划线并显示 The type 'Generic:List' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built

【问题讨论】:

    标签: visual-studio-2010 silverlight xaml mvvm devforce


    【解决方案1】:

    尝试在 XAML 中使用 System.Collections.Generic.List&lt;T&gt; 的问题在于(据我所知)XAML 的 Silverlight 方言无法指定泛型类型参数的值。您收到的错误是因为没有类型 System.Collections.Generic.List 没有类型参数。

    您可以做的一件事是创建List&lt;T&gt; 的子类,它为类型参数提供一个值,但不包含新的或覆盖的成员,例如:

    public class ASTInsuranceList : List<ASTInsurance>
    {
    }
    

    然后,您可以在 XAML 中使用 ASTInsuranceList 对象来包含 ASTInsurance 对象的列表。

    【讨论】:

    • 宾果游戏!这行得通。必须使用 Collection 源而不是添加单独的设计数据。
    猜你喜欢
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多