Monday, 15 February 2010

c# - ListBox does not use all available space within Grid.Column - WPF -



c# - ListBox does not use all available space within Grid.Column - WPF -

i have listbox command has been assigned grid.column 0 has value of '*' defined it's width, when rendered there sizeable amount of space not beingness used.

i have noticed there border of sorts around listbox command itself, have not added 1 within markup.

my ui (areas of concern marked in red):

my markup:

<window.resources> <datatemplate x:key="gameimagestemplate" > <stackpanel orientation="vertical"> <image source="{binding fileinfo.fullname}" margin="8,8,8,8" height="70" width="70" /> <label content="{binding name}" width="70" /> </stackpanel> </datatemplate> <datatemplate x:key="gametemplate"> <stackpanel> <label content="{binding name}" background="gray" fontsize="16" /> <listbox x:name="imagecontent" itemssource="{binding filelist}" itemtemplate="{staticresource gameimagestemplate}" scrollviewer.horizontalscrollbarvisibility="disabled" > <listbox.itemspanel> <itemspaneltemplate> <wrappanel orientation="horizontal" isitemshost="true" /> </itemspaneltemplate> </listbox.itemspanel> </listbox> </stackpanel> </datatemplate> </window.resources> <grid> <grid.columndefinitions> <columndefinition width="*"/> <columndefinition width="auto"/> </grid.columndefinitions> <listbox x:name="contentlist" itemtemplate="{staticresource gametemplate}" grid.column="0" scrollviewer.horizontalscrollbarvisibility="disabled" /> <stackpanel grid.column="1" background="darkgray"> <button click="onload">_load</button> <button click="onsave">_save</button> <button click="onadd">_add</button> <button click="ondelete">_delete</button> </stackpanel> </grid>

how go resolving both of issues raised. default behaviour of listbox control?

many thanks

yes, default behavior.

in case of alignment looks have wrappanel in each listboxitem doesn't have quite plenty space set item on line 1. remaining space unused because of horizontalcontentalignment setting on listbox defaulting left. setting in turn bound default listboxitem. setting horizontalcontentalignment="stretch" on listbox should prepare that.

the outer border comes default setting borderbrush , borderthickness. setting borderthickness="0" rid of entirely.

there other default padding settings add together spacing in default styles , templates. if want more add together listbox project in blend , create re-create of default template , itemcontainerstyle , check out xaml. consider using base of operations itemscontrol in cases don't need selection behavior, doesn't have of these type of default settings.

c# wpf .net-4.0 listbox grid-layout

No comments:

Post a Comment