首页 文章

可以使用带有datatemplate的wrappanel进行列表框中项目的水平对齐

提问于
浏览
2

我正在尝试水平对齐列表框中的项目(项目是复选框项目) . 如何使用带有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>

1 回答

  • 8

    我想你想要 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>
    

相关问题