0

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

一个客户端是这样创建的

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 中的每个标题都是一个计划名称,每个标题都将展开以显示计划中的分配。我还需要一个名为“Common Allocations”的单独标题,它可以展开以显示所有计划共有的分配。我似乎无法找到一种方法来做到这一点。我可以将计划正确地绑定到 Accordion 的 ItemsSource 属性,但是我不能将公共分配添加为单独的项目,因为一旦绑定了计划,Accordion 的项目集合就变为只读的。我也不想为公共分配创建单独类型的计划,因为公共分配实际上并不代表客户的计划。任何帮助,将不胜感激。

4

1 回答 1

0

如何为您的 Accordian 的 ItemsSource 创建一个分配集合。

像这样创建集合:

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

    yield return c.Plans.CommonAllocations;
}

如果需要,将其公开为 Binding 属性:

public IEnumerable<Allocation> AllAllocations
{
    get
    {
        return GetAllAllocations(new Client() { Name = "Acme Company" });
    }
}
于 2013-03-06T22:15:36.033 回答