我想仅使用XAML将集合绑定到ListBox。它有些作品,但它只显示MyProject.mainItem
(这是对象类型),而不是实际值。简单绑定的问题
在分配为在DataContext类的,我有这样的:
ItemCatalog.Add(new mainItem { Ref = "555555", ItemName = "First Item" });
在具有列表框页面上的XAML,我有这样的:
<ListBox ItemsSource="{Binding ItemCatalog}">
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding Ref}" TextWrapping="Wrap" Foreground="Black" />
<TextBlock Text="{Binding ItemName}" TextWrapping="Wrap" Margin="12,-6,12,0" Foreground="Black" />
</StackPanel>
</DataTemplate>
</ListBox>
它循环通过整个ItemCatalog
集合,但不是显示值如First Item
,而是显示对象的类型。谢谢
我以前没有使用silverlight,但有没有DataSource属性或“TextBlock”? – EJC 2010-09-30 03:45:05