我试图使用代码绑定XAML ListBoxItem,但似乎不起作用
在我的XAML中:
发布于 2010-12-15 10:08:24
您不需要根据代码创建ListBoxItem。
您只需提供一个包含CLR类对象集合的ListBox,提供一个ItemTemplate,它将ItemTemplate隐式包装在ListBoxItem中。
示例:
public class FooList
{
public ObservableCollection<String> Items { get; set; }
public FooList()
{
Items = new ObservableCollection<String>();
}
}XAML:
<ListBox x:Name="ListBox1" ItemsSource="{Binding Path=Items, Source={StaticResource FooListItem}}" />发布于 2010-12-15 10:09:28
https://stackoverflow.com/questions/4448571
复制相似问题