2013-03-06 89 views
0

有没有办法将集合绑定到Silverlight中的Accordion控件,但是其中一个Accordion项目是该集合通用的项目列表。例如,我有几种类型:Client,PlanCollection,Plan,AllocationCollection,Allocation。每个客户都有一个或多个计划,每个计划都有一个或多个分配。一些分配对所有计划都是共同的。公共分配本身包含在客户计划集合的分配集合属性中。这里有一些示例代码来克莱利。在Silverlight中自定义绑定到手风琴控件

客户端是这样

Client c = new Client() { Name = "Acme Company" }; 

计划的拨款将访问这样的事情

c.Plans["Acme DB Plan"].Allocations 

单一的分配将访问这样的事情

Allocation first = c.Plans["Acme DB Plan"].Allocations[0]; 
创建

一个计划的共同分配将被访问像这样

c.Plans.CommonAllocations; 

而且这样

Allocation firstCommon = c.Plans.CommonAllocations[0]; 

在手风琴每个头一个共同的分配将是一个计划名称和每个头将扩大,以揭示该计划的拨款。我还需要一个名为“通用分配”的单独标题,该标题可扩展以显示所有计划共有的分配。我似乎无法想出办法做到这一点。我可以将计划正确地绑定到Accordion的ItemsSource属性,但我无法将常用分配作为单独的项目添加,因为一旦计划被绑定,Accordion的项目集合就变为只读。我也不想为公共分配创建单独的计划类型,因为公共分配实际上并不代表客户的计划。任何帮助,将不胜感激。

回答

0

如何为您的手风琴的ItemsSource创建分配集合。

像这样创建集合:

IEnumerable<Allocation> GetAllAllocations(Client c) 
{ 
    foreach (var plan in c.Plans) 
    { 
     yield return plan.Allocations; 
    } 

    yield return c.Plans.CommonAllocations; 
} 

并将其作为一个物业绑定,如果你需要:

public IEnumerable<Allocation> AllAllocations 
{ 
    get 
    { 
     return GetAllAllocations(new Client() { Name = "Acme Company" }); 
    } 
}