Wpf 可以将wrappanel与datatemplate一起用于列表框中项目的水平对齐

Wpf 可以将wrappanel与datatemplate一起用于列表框中项目的水平对齐,wpf,xaml,Wpf,Xaml,我正在尝试水平对齐列表框中的项目(项目是复选框项目)。如何将包装面板与datatemplate一起使用 <ListBox Name="Horizontal" ItemsSource="{Binding Solution}" scrollViewer.HorizontalScrollBarVisibility="Disabled" > <ListBox.ItemTemplate > <DataTemplate > <CheckBox Conten

我正在尝试水平对齐列表框中的项目(项目是复选框项目)。如何将包装面板与datatemplate一起使用

<ListBox  Name="Horizontal"  ItemsSource="{Binding Solution}" scrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListBox.ItemTemplate >
 <DataTemplate >
  <CheckBox Content="{Binding Name}" IsChecked="{Binding IsChecked}" Margin="5 5 0 0"/>
  </DataTemplate>
 </ListBox.ItemTemplate>
</ListBox>

我想您需要
ItemsPanel
属性:

<ListBox Name="Horizontal" ItemsSource="{Binding Solution}" scrollViewer.HorizontalScrollBarVisibility="Disabled">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Content="{Binding Name}" IsChecked="{Binding IsChecked}" Margin="5 5 0 0"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

将包装纸放入ListBox.ItemsPanel中。