2009-06-28 22 views
0

我有一個wpf用戶控件,它公開IEnumerable ItemsSource DependencyProperty。我將此屬性綁定到我的UserControl中的ListBox控件。如何使我的WPF UserControl與CompositeCollection一起工作

我想知道如何在給出CompositeCollection時讓我的用戶控件工作。目前我使用我的控制是這樣的:

<my:uc> 
    <my:uc.ItemsSource> 
    <CompositeCollection> 
     <CollectionContainer Collection="{My Binding}"></CollectionContainer> 
     <CollectionContainer Collection="{My Binding}"></CollectionContainer> 
    </CompositeCollection> 
    </my:uc.ItemsSource> 
</my:uc> 

我想這顯示在列表框中這些CollectionContainers的內容,但目前它不是通過容器枚舉。我的列表框顯示的唯一項目是兩個「System.Data.CollectionContainer」項目。

[b]編輯:[/ b]XAML設計者通知我「Property'ItemsSource'不支持'CompositeCollection'類型的值。我認爲這是我的問題..但我怎麼讓它「支持」CompositeCollection?

回答

0

正確的答案是創建一個擴展ItemsControl的類。設計控件時不能使用任何XAML,但它確實會爲您提供支持CollectionContainers的特殊ItemsSource屬性。該控件的視圖應該在其ContentTemplate屬性中定義。

0

我認爲,你得到是你的對象,它在默認情況下返回類型的名稱的ToString方法。

嘗試覆蓋ToString並返回想要在列表中看到的值。

+0

的問題是,CollectionContainer不應該表現自己所有,而是需要提供其子元素。 – 2009-06-28 14:26:10

相關問題