Reputation: 386
I am trying to get list items to stack from left to right as oppose to top to bottom.
<ListBox x:Name="listBox1" HorizontalAlignment="Stretch" Height="454" Margin="10,10,0,0" VerticalAlignment="Top" Width="943">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="3.0"/>
<Setter Property="Width" Value="Auto" />
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Margin" Value="3,3,3,3"/>
<Setter Property="FontSize" Value="16"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Right" FlowDirection="LeftToRight">
<Grid>
<TextBlock Text="Machine Name:" />
</Grid>
<Grid>
<TextBlock Text="{Binding Mname}" />
</Grid>
<Grid>
<TextBlock Text="{Binding PartName}" />
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I can only seem to get them to stack on top of each other. Any of the alignments I change seems to generally have no effect.
I have tried wrapping a Grid
around the StackPanel
with FlowDirection="LeftToRight" HorizontalAlignment="Stretch"
but I have only been able to get the list items to be directly in the center of the window, or on the left stacked on top of each other.
Upvotes: 0
Views: 2049
Reputation: 37059
<ListBox
...
>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel
Orientation="Horizontal"
/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Upvotes: 2
Reputation: 2785
You want Orientation="Horizontal"
StackPanel.Orientation property
Upvotes: 2