您使用ItemsControl
(默认情况下使用Stackpanel
把其项目)
<ItemsControl ItemsSource="{Binding ListOfStringsProperty}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}" />
</DataTemplate>
</ItemsControl>
</ItemsControl>
真正的技巧,虽然将作出单击该按钮时,有用的事情发生。最基本的方法是在代码隐藏中有一个Button_Click
事件。
编辑: “我怎样才能改变方向,以横”
<ItemsControl ItemsSource="{Binding ListOfStringsProperty}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}" />
</DataTemplate>
</ItemsControl>
</ItemsControl>
@Yanshof:见我的编辑。 – AnthonyWJones