在ListBox中有一个ItemCollection?

时间:2017-09-04 21:25:54

标签: wpf xaml listbox

我想知道为什么以下xaml代码不起作用。

<ListBox>
<ListBox.Items>
<ItemCollection>
<ListBoxItem><TextBlock>A</TextBlock></ListBoxItem>
<ListBoxItem><TextBlock>B</TextBlock></ListBoxItem>
<ListBoxItem><TextBlock>C</TextBlock></ListBoxItem>
</ItemCollection>
</ListBox.Items>
</ListBox>

它说 类型“ItemCollection”不包含任何可访问的构造函数 这条消息意味着什么,以及如何解决它?

1 个答案:

答案 0 :(得分:0)

<ListBox>
<ListBoxItem><TextBlock>A</TextBlock></ListBoxItem>
<ListBoxItem><TextBlock>B</TextBlock></ListBoxItem>
<ListBoxItem><TextBlock>C</TextBlock></ListBoxItem>
</ListBox>

您不必将ItemCollection和Items标记放在WPF将在内部执行。