现在的位置: 首页 > 综合 > 正文

WPF listbox WrapPanel Horizontal无效的原因

2011年04月21日 ⁄ 综合 ⁄ 共 737字 ⁄ 字号 评论关闭

http://stackoverflow.com/questions/4244793/listbox-not-showing-items-horizontally-after-using-theme

           <ListBox.ItemsPanel>

<ItemsPanelTemplate>

<WrapPane Orientation="Horizontal"l></WrapPanel>

</ItemsPanelTemplate>

</ListBox.ItemsPanel>

无法正常横向显示,原因应用了Theme,修改对应的Theml.xaml

<ControlTemplate TargetType="{x:Type ListBox}">
<Grid>
<Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" Background="{DynamicResource ControlBackgroundBrush}" />
<ScrollViewer Margin="1" Style="{DynamicResource NuclearScrollViewer}" Focusable="false" Background="{x:Null}">
<StackPanel Margin="1,1,1,1" IsItemsHost="true" />
</ScrollViewer>
</Grid>

修改 StackPanel to an ItemsPresenter:

<ItemsPresenter Margin="1,1,1,1"/>

抱歉!评论已关闭.