Coder
Coder

Reputation: 93

Can use a wrappanel with datatemplate for horizontal alignment of items in a listbox

I am trying to horizontally align items in a listbox(items are checkbox items). How can i use a wrap panel with 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>

Upvotes: 2

Views: 4321

Answers (1)

Kevin DiTraglia
Kevin DiTraglia

Reputation: 26048

I think you want the ItemsPanel property:

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

Upvotes: 8

Related Questions