如果只是单纯的让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