【问题标题】:listbox items orientation to horizontal列表框项目方向为水平
【发布时间】:2011-04-03 16:38:48
【问题描述】:

如何在列表框的默认样式中使列表框项目方向为水平。 我的意思是默认情况下我们使用混合获得的样式。

【问题讨论】:

    标签: c# silverlight silverlight-4.0


    【解决方案1】:

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

    <ListBox>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>
    

    如果您想在样式中执行此操作,只需添加一个设置 ItemsPanel 属性的 Setter:

    <Style TargetType="ListBox">
        <!-- Rest of the style -->
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    【讨论】:

    • tx Quartermeister 以获得答案,但我想从默认样式中执行此操作。我将只编辑样式
    • 嘿 Quartermeister tx 再一次,但在样式完成时会抛出一个错误:消息:Silverlight 应用程序项目集合中的未处理错误在使用 ItemsSource 之前必须为空。在 System.Windows.Controls.ItemsControl.set_ItemsSource(IEnumerable 值)
    • @Malcom:很难看出这是如何破坏它的。如果您完全保留 ItemsPanelTemplate 属性,将其保留为默认的垂直堆栈面板,您还会收到错误消息吗?
    • 哎呀抱歉这个错误是针对不同的问题。但它没有显示数据。他的解决方案是 ..tx Quartermeister
    • 我想根据页面方向的变化动态地将方向水平更改为垂直。有可能吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    相关资源
    最近更新 更多