Creating a Windows Phone app: Listbox items of the same width
Join the DZone community and get the full member experience.Join For Free
i love databound listboxes in wp7. i do. i really do. however, every time i come to the part of making a nice template for each item (i.e. shiny ugly orange border, etc.) i fail in having items of equal size. this is usally what i produce:
in wpf, the trick is to set the horizontalalignment=”stretch” property of the listbox. however, apparently there still some internal bug in the listbox control, which results in the listbox simply ingoring that setting.
the solution however is, luckily, provided by microsoft’s peter torr in a reply in
by simply adding the itemcontainerstyle as described in the post , to the listbox we get the result we are looking for:
resulting in ..hooray:
update: as alex sorokoletov was so kindly to cmment (thanks for that), there’s even a simplier solution:
<listbox.itemcontainerstyle> <style targettype=”listboxitem”> <setter property=”horizontalalignment” value=”stretch” /> <setter property=”horizontalcontentalignment” value=”stretch”/> </style> </listbox.itemcontainerstyle>
Opinions expressed by DZone contributors are their own.