WPF listbox WrapPanel Horizontal无效的原因

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"/>






原文地址:https://www.cnblogs.com/rock_chen/p/2322537.html