<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" >
</UniformGrid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem HorizontalContentAlignment="Stretch">listbox item 1</ListBoxItem>
<ListBoxItem>listbox item 2</ListBoxItem>
<ListBoxItem>listbox item 3</ListBoxItem>
<ListBoxItem>listbox item 4</ListBoxItem>
<ListBoxItem>listbox item 5</ListBoxItem>
</ListBox>
I have added ListBoxItems as above and used UniformGrid to display it. but I can't achieve content based width for each of the list box item. I have tried HorizontalContentAlignment as Stretch and Auto width properties. Nothing happened.
You have to use
HorizontalAlignmentinstead ofHorizontalContentAlignment.If you want to set the alignment for all items, consider creating an item container style.
Please note that the default value for
HorizontalAlignmentis alreadyStretch, so you will not see a difference there. Furthermore, there is noAuto. The possible values areLeft,Right,CenterandStretch. All values except forStretchwill size to the content.