我想知道为什么以下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”不包含任何可访问的构造函数 这条消息意味着什么,以及如何解决它?
答案 0 :(得分:0)
<ListBox>
<ListBoxItem><TextBlock>A</TextBlock></ListBoxItem>
<ListBoxItem><TextBlock>B</TextBlock></ListBoxItem>
<ListBoxItem><TextBlock>C</TextBlock></ListBoxItem>
</ListBox>
您不必将ItemCollection和Items标记放在WPF将在内部执行。