c# - Height of ListBoxItem in VirtualizingStackPanel -
i'm developing app entire ui sized percentage. therefore height of listboxitems needs controlled too. i'm having problems getting work.
listboxstyle:
<style x:key="listboxstyle" targettype="{x:type listbox}"> <setter property="stylus.ispressandholdenabled" value="false" /> <setter property="template"> <setter.value> <controltemplate targettype="{x:type listbox}"> <border borderbrush="{staticresource controlborderbrush}" background="{staticresource controlbackgroundbrush}"> <scrollviewer scrollviewer.verticalscrollbarvisibility="auto" scrollviewer.horizontalscrollbarvisibility="disabled"> <virtualizingstackpanel isitemshost="true" virtualizingstackpanel.virtualizationmode="recycling"> </virtualizingstackpanel> </scrollviewer> </border> </controltemplate> </setter.value> </setter> </style>
listboxitemstyle:
<style targettype="{x:type listboxitem}"> <setter property="stylus.ispressandholdenabled" value="false" /> <setter property="focusvisualstyle" value="{x:null}" /> <setter property="foreground" value="{staticresource controltextnormalbrush}"/> <setter property="borderthickness" value="1,0,1,1"/> <setter property="template"> <setter.value> <controltemplate targettype="listboxitem"> <border name="border" height="height="{binding converter={staticresource percentageconverter}, path=actualheight, converterparameter=10}"" snapstodevicepixels="true" borderthickness="{templatebinding borderthickness}" borderbrush="{staticresource controlitemborderbrush}" background="{staticresource controlitemnormalbackgroundbrush}"> <contentpresenter/> </border> <controltemplate.triggers> <trigger property="ismouseover" value="true"> <setter targetname="border" property="background" value="{staticresource controlitemhoverbackgroundbrush}"/> </trigger> <trigger property="isselected" value="true"> <setter targetname="border" property="background" value="{staticresource controlitemselectedbackgroundbrush}" /> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> <style.triggers> <trigger property="isselected" value="true"> <setter property="foreground" value="{staticresource controltextselectedbrush}"/> </trigger> <datatrigger binding="{binding relativesource={relativesource self}, converter= {staticresource firstitemconverter}}" value="true"> <setter property="borderthickness" value="1,1,1,1" /> </datatrigger> </style.triggers> </style>
i have percentageconverter use other places to, works charm. looks in scenario, never called or not have effect. height of items larger listbox itself.
using uniformgrid itemspanel listbox evenly space items:
<listbox> <listbox.itemspanel> <itemspaneltemplate> <!-- change rows="1" if want horizontal layout --> <uniformgrid columns="1" /> </itemspaneltemplate> </listbox.itemspanel> <listbox.items> <listboxitem>item 1</listboxitem> <listboxitem>item 2</listboxitem> <listboxitem>item 3</listboxitem> <listboxitem>item 4</listboxitem> <listboxitem>item 5</listboxitem> <listboxitem>item 6</listboxitem> <listboxitem>item 7</listboxitem> <listboxitem>item 8</listboxitem> </listbox.items> </listbox>
now 8 items each have 12.5% height (1/8) , 100% width (1/1). this page explains workings of uniformgrid
.
Comments
Post a Comment