簡體   English   中英

在Silverlight中自定義綁定到手風琴控件

[英]Custom binding to Accordion control in Silverlight

有沒有一種方法可以將集合綁定到Silverlight中的“手風琴”控件,但是“手風琴”項之一是該集合共有的項的列表。 例如,我有幾種類型:客戶端,計划集合,計划,AllocationCollection,分配。 每個客戶都有一個或多個計划,每個計划都有一個或多個分配。 一些分配是所有計划共有的。 公用分配本身包含在客戶的計划集合的分配集合屬性中。 這里是一些示例代碼。

這樣創建一個客戶端

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

手風琴中的每個標題將是一個計划名稱,每個標題將展開以顯示計划中的分配。 我還需要一個單獨的標題“ Common Allocations”,該標題可以擴展以顯示所有計划共有的分配。 我似乎想不出辦法。 我可以將計划正確綁定到“手風琴”的ItemsSource屬性,但是不能將公共分配作為單獨的項目添加,因為一旦綁定了計划,“手風琴”的項目集合將變為只讀。 我也不想為公用分配創建單獨的計划類型,因為公用分配實際上並不代表客戶的計划。 任何幫助,將不勝感激。

如何為Accordian的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" });
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM