我在WP8中有一个ListBox
控件
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Height="120" Width="410" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem Margin="0,0,20,0" Width="120" Height="120" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
ListBoxItem 1
</ListBoxItem>
<ListBoxItem Margin="0,0,20,0" Width="120" Height="120" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
ListBoxItem 2
</ListBoxItem>
<ListBoxItem Margin="0,0,10,0" Width="120" Height="120" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
ListBoxItem 3
</ListBoxItem>
</ListBox>
现在我必须在运行时添加此ListBox
。我可以设法添加ListBoxItems
但无法设置ItemsPanelTemplate
。请帮忙。
答案 0 :(得分:0)
ListBox lb = new ListBox();
ItemsPanelTemplate ddd = new ItemsPanelTemplate();
lb.ItemTemplate = ddd;
xaml中的所有内容都是类。记住它。