Simple Silverlight question: I have an ObservableCollection<MyObject> in my viewmodel. Every MyObject has a Label property. If I bind a ListBox to the collection and set DisplayMemberPath to Label, or set the ItemTemplate to a TextBlock that binds the Text property to Label, all works as expected.
If I change MyObject so it derives from a UserControl, the Label text no longer shows up in the ListBox; each item just shows up as a blank strip a few pixels tall. Why is 开发者_运维知识库this? There's obviously something I'm missing here about how different things get rendered.
The ListBox determines that the set of items in its ItemsSource
are already UIElement
instances and therefore decides to use those elements directly as the content of the ListBoxItem
elements it creates.
精彩评论