WPF ListBox 横向排列

  如果只是单纯的让ListBox可以横向配列,这样很简单,只需要更改ListBox的ItemsPanel模板就可以,例如:

<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation=”Horizontal” IsItemsHost=”True”/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

  但是这样的修改,ListBox只能横向排列,不会根据宽度自动换行,如果想要横向排列的ListBox支持根据宽度自动换行的话,需要这样写:

<ListBox.Template>
<ControlTemplate TargetType=”{x:Type ListBox}”>
<ScrollViewer HorizontalScrollBarVisibility=”Disabled” VerticalScrollBarVisibility=”Auto”>
<WrapPanel Orientation=”Horizontal” IsItemsHost=”True” ScrollViewer.CanContentScroll=”True”/>
</ScrollViewer>
</ControlTemplate>
</ListBox.Template>

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net

原文地址:https://www.cnblogs.com/sjwudhwhhw/p/10442835.html

时间: 2024-08-29 23:03:29

WPF ListBox 横向排列的相关文章

listbox横向排列

在Listbox中横向显示CheckBox 前台代码 1 <ListBox Height="30" HorizontalAlignment="Left" Margin="231,25,0,0" Name="listMonth" VerticalAlignment="Top" Width="747" > 2 <StackPanel x:Name="sp"

wpf listbox横向布局

<ListBox Grid.Row="1" x:Name="lstStaffs"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBo

WPF Datagrid横向排列

1 <DataGrid.ItemsPanel> 2 <ItemsPanelTemplate> 3 <StackPanel Orientation="Horizontal"/> 4 </ItemsPanelTemplate> 5 </DataGrid.ItemsPanel> 记录一下.

Template、ItemsPanel、ItemContainerStyle、ItemTemplate(包括ListBox的Item子项是横向排列)

Template.ItemsPanel.ItemContainerStyle.ItemTemplate 分类: WPF2011-10-12 10:13 4716人阅读 评论(0) 收藏 举报 datagridwpftree 先来看一张图(网上下的图,加了几个字) 实在是有够“乱”的,慢慢来理一下: 1.Template是指控件的样式 在WPF中所有继承自contentcontrol类的控件都含有此属性,(继承自FrameworkElementdl类的TextBlock等控件无).Template

无序列表li横向排列的间隙问题

今天在写页面的时候,无意中遇到这样一个问题,就是无序列表li横向排列即做成导航栏时,列表项间有间隙. 如: 将列表项li变成列表块后(即将li标签设置为,display:inline-block后),会变成这样,中间会有间隙. 即便是将外边距.内边距都设为0后,还是有间隙.在调试了很久,还是没法解决这个问题,最后我改变了一下li的位置,结果可以了.我是这样做的. 改变li的位置后,结果如下: 好,问题成功解决了.不知园友们还有没有其他的好办法,欢迎指教.

【CSS技巧】列表横向排列的另一种方法

列表<ul><dl>等默认是纵向排列.我们需要它横向排列时通常会用float来实现,但是使用了float也通常会引发一些排版问题.今天我学到了另一种方法:设定<li>标签的display:inline,把<li>设定为内联元素来实现横向排列的效果,不需要使用float. <!doctype html> <html> <head> <meta charset="utf-8"> <titl

如何让div横向排列

方法一: 一般情况,默认的div是写一个换一行,那么如何定义两个div横向排列而不换行呢? div默认的display属性是block.所以每一个div都是新的一行,现在把display换成inline就不会换新行了. <div style="display:inline;">aaa</div><div style="display:inline;">bbb</div> 方法二: 这里使用float:right属性.f

HTML+CSS-如何定义让两个div横向排列

方法一: 一般情况,默认的div是写一个换一行,那么如何定义两个div横向排列而不换行呢? div默认的display属性是block.所以每一个div都是新的一行,现在把display换成inline就不会换新行了. <div style="background-color:#ff0000;display:inline;">aaa</div> <div style="background-color:#ffff00;display:inline

横向排列两个多个div盒子的方法(CSS浮动清除float-clear/inline)/办法

最近在做一个div css切割,昨晚发现了长期以来一直无记录下来的问题!关于兼容IE跟FF的float属性.趁现在还清醒赶紧记下笔记先:一.并排在一行的两个div样式有这种情况:ie或者ff下对于子div设置float左的时候,如果另外的子div没有设置float左的 话,两个浏览器下会有区别,具体有一个会产生间隙.兼容做法就是都设置float属性.但是记住有设置过float就要将float clear掉,不然下面的div会叠在已float的div上.我通常把清除浮动写成单独的<div clas