c# - WPF ListBoxItem does not stretch to the maximum width in wrappanel -
i trying make listbox contains custom control , wrap automic.my listbox xaml code below.i need 3 items in each row , stretch maximum width.it wrap next row if items more three. need custom control stretch on in horizontal not both side. how can that?
<scrollviewer horizontalscrollbarvisibility="disabled"> <listbox> <listbox.template> <controltemplate targettype="{x:type listbox}"> <wrappanel orientation="horizontal" isitemshost="true" /> </controltemplate> </listbox.template> <listboxitem> <controls:transduceritem margin="5,10"/> </listboxitem> <listboxitem> <controls:transduceritem margin="5,10"/> </listboxitem> <listboxitem> <controls:transduceritem margin="5,10"/> </listboxitem> <listboxitem> <controls:transduceritem margin="5,10" /> </listboxitem> <listboxitem> <controls:transduceritem width="200" margin="5,10" /> </listboxitem> </listbox>
use uniformgrid 3 columns itemspanel
:
<listbox> <listbox.itemspanel> <itemspaneltemplate> <uniformgrid columns="3" verticalalignment="top"/> </itemspaneltemplate> </listbox.itemspanel> ... </listbox>
you might use transduceritem control in itemtemplate
of listbox
<listbox.itemtemplate> <datatemplate> <controls:transduceritem margin="5,10"/> </datatemplate> </listbox.itemtemplate>
and bind listbox's itemssource
property collection of data items hold each transduceritem's data:
<listbox itemssource="{binding tranducerdata}"> ... </listbox>
take @ data templating overview article on msdn.