列表框项目方向为水平

Mal*_*olm 15 c# silverlight silverlight-4.0

如何在列表框的默认样式中将列表框项目方向设置为水平.我的意思是默认是我们使用混合的样式.

Qua*_*ter 30

使用ItemsPanel属性将面板替换为水平StackPanel:

<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

如果要在Style中执行此操作,只需添加一个Setter来设置ItemsPanel属性:

<Style TargetType="ListBox">
    <!-- Rest of the style -->
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)