我的WPF应用程序正在生成动态按钮.我想要水平显示这些按钮.我为此编写了代码.代码工作正常,但不是在水平方向显示按钮,它显示垂直方向的所有按钮!我也设置Orientation了StackPanel!
谁能解决我的问题?
我的代码是:
<Grid>
<dxlc:ScrollBox>
<ItemsControl x:Name="Buttonslist">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Content="{Binding Text}" Tag="{Binding Text}" x:Name="New" Margin="5,0,5,0" Click="New_Click" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</dxlc:ScrollBox>
</Grid>
Run Code Online (Sandbox Code Playgroud)
Chr*_*ris 14
您实际上是为每个项目/按钮创建一个StackPanel.要获得所有项目的一个,您需要ItemsPanel将控件设置为StackPanel.
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Text}" Tag="{Binding Text}" x:Name="New" Margin="5,0,5,0" Click="New_Click" />
</DataTemplate>
</ItemsControl.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3183 次 |
| 最近记录: |