如何在列表框的默认样式中将列表框项目方向设置为水平。 我的意思是默认是我们使用混合的样式。
答案 0 :(得分:29)
使用ItemsPanel属性将面板替换为水平StackPanel:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
如果您想在Style中执行此操作,只需添加一个设置ItemsPanel属性的Setter:
<Style TargetType="ListBox">
<!-- Rest of the style -->
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>