在XAML中,绑定所有数组条目到我的ListBox存在问题。
XAML:
<ListBox ItemsSource="{Binding ResultFlag}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TypeInfo}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>ResultFlag属性在ViewModel中(它是XAML文件的DataContext ):
private ObservableCollection<DataField> _resultFlag;
public ObservableCollection<DataField> ResultFlag
{
get { return _resultFlag; }
set
{
_resultFlag = value;
OnPropertyChanged();
}
}TypeInfo在DataField类中:
public string[] TypeInfo { get; set; }我想在ListBox中显示上述数组中的所有字符串条目--我应该如何做到这一点?我尝试了几种方法,包括嵌套Listbox和直接将ListBox的ItemsSource绑定到数组(不起作用,BTW)
干杯!
发布于 2015-12-10 20:21:08
您在场景中拥有的是一个列表。为了显示在列表框中,您需要像这样嵌套ListBoxes。
<ListBox ItemsSource="{Binding ResultFlag}" >
<ListBox.ItemTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding TypeInfo}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>https://stackoverflow.com/questions/34210645
复制相似问题