vb.net - WPF - Usercontrol as ListItemTemplate not filling listbox width -
just trying head round wpf. have usercontrol i'm using template items in listbox, no matter try usercontrol's width shrinking minimum size want fill available width. i've found similar query on here relating usercontrol not within listbox , solution proposed doesn't apply here.
my usercontrol defined :
<usercontrol x:class="ureportitem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="60" d:designwidth="300"> <grid > <border cornerradius="3,3,3,3" borderbrush="#0074ba" borderthickness="1" background="#00d6f9" margin="0"> <dockpanel margin="3,3,3,3"> <grid height="auto"> <!-- grid definition--> <grid.rowdefinitions> <rowdefinition height="auto"></rowdefinition> <rowdefinition height="auto"></rowdefinition> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="auto"></columndefinition> <columndefinition></columndefinition> <columndefinition width="auto"></columndefinition> </grid.columndefinitions> <!-- content --> <!-- top row--> <button grid.rowspan="2">delete</button> <stackpanel orientation="horizontal" grid.column="1"> <label x:name="heading" content="{binding heading}" fontsize="14" fontweight="bold"></label> <label x:name="subheading" content="{binding subheading}" fontsize="14"></label> </stackpanel> <button grid.column="2">blah</button> <!-- second row--> <label grid.row="1" grid.column="1" x:name="comments">comments</label> <button grid.column="2">blah</button> </grid> </dockpanel> </border> </grid> and implementation on window :
<window x:class="vreport" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:recorderui" title="vreport" height="300" width="300" background="#00bcf0"> <window.resources> <datatemplate x:key="record" datatype="listitem"> <grid> <local:ureportitem></local:ureportitem> </grid> </datatemplate> <style targettype="listboxitem"> <setter property="isselected" value="{binding isselected, mode=twoway}" /> </style> </window.resources> <grid> <grid.rowdefinitions> <rowdefinition height="auto"></rowdefinition> <rowdefinition></rowdefinition> <rowdefinition height="auto"></rowdefinition> </grid.rowdefinitions> <local:ureport margin="5" grid.row="0"></local:ureport> <border grid.row="1" borderbrush="#0074ba" cornerradius="3"> <listbox margin="5" background="#00d6f9" borderbrush="#0074ba" x:name="listrecords" itemssource="{binding items}" itemtemplate ="{staticresource record}"></listbox> </border> <textblock grid.row="2" x:name="selecteditem" text="{binding path=selecteditem.heading, mode=twoway}"></textblock> </grid> any ideas?
try setting horizontalcontentalignment stretch on listbox:
<listbox margin="5" background="#00d6f9" borderbrush="#0074ba" x:name="listrecords" itemssource="{binding items}" itemtemplate ="{staticresource record}" horizontalcontentalignment="stretch"></listbox>
Comments
Post a Comment