我注意到,如果您有任何从SilverlightUIElement
中的项目派生的东西,ListBox
它会按原样呈现对象,并且不会关注DisplayMemberPath
和/或的设置ListBox.ItemTemplate
。
例如,如果您有这样的 XAML:
<ListBox Width="200" Height="300" DisplayMemberPath="Tag">
<TextBlock Tag="tag1">text1</TextBlock>
<TextBlock Tag="tag2">text2</TextBlock>
<TextBlock Tag="tag3">text3</TextBlock>
</ListBox>
在 Silverlight 中,这会产生一个ListBox
类似这样的项目:
text1
text2
text3
但是在 WPF 中(我认为这是正确的行为)它按预期列出了标签:
tag1
tag2
tag3
如果我使用不是从 UIElement 继承的对象,一切都会按预期工作:
<ListBox Width="200" Height="300" DisplayMemberPath="[0]">
<sys:String>abcde</sys:String>
<sys:String>fgh</sys:String>
</ListBox>
产生:
a
f
有什么方法可以像在 Silverlight 中一样使用UIElement
s 和任何其他对象一样?ItemsSource
还是我错过了什么?