0
votes

Is there a way to bind a collection to an Accordion control in Silverlight but have one of the Accordion items be a list of items common to the collection. For example, I have several types: Client, PlanCollection, Plan, AllocationCollection, Allocation. Each client has one or more plans and each plan has one or more allocations. Some of the allocations are common to all the plans. The common allocations themselves are contained in an allocation collection property of the plan collection of a client. Here is some sample code to clariy.

A client is created like this

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

The allocations of a plan would be accessed something like this

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

A single allocation would be accessed something like this

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

The allocations common to a plan would be accessed something like this

c.Plans.CommonAllocations;

And a single common allocation like this

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

Each header in the Accordion will be a plan name and each header will expand to reveal the allocations in the plan. I also need a separate header called "Common Allocations" that expands to reveal the allocations common to all plans. I can't seem to figure out a way to do this. I can bind the plans correctly to the ItemsSource property of the Accordion, but I can't add the common allocations as a separate item because once the plans are bound the item collection of the Accordion becomes read-only. I also don't want to create a separate type of plan for the common allocations because the common allocations don't actually represent a plan of the client. Any help would be appreciated.

1

1 Answers

0
votes

How about creating a collection of Allocations for the ItemsSource of your Accordian.

Create the collection like this:

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

    yield return c.Plans.CommonAllocations;
}

And expose it as a Property for Binding if you need:

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