c# - Why are ListBoxItems added in XAML not styled? -
why listboxitems declared within xaml not affected datatemplate? template fine when bind source, , that's i'll doing ultimately, wondering why declared items aren't styled.
<listbox> <listbox.itemtemplate> <datatemplate> <grid> <textblock text="{binding}" foreground="red"/> </grid> </datatemplate> </listbox.itemtemplate> <listboxitem>lbi 1</listboxitem> <listboxitem>lbi 2</listboxitem> </listbox>
here lbi 1 , lbi 2 not red if use listbox.itemsource , bind list, items red.
you need apply style
. datatemplate
used apply template data
bound listbox. hence not applying items directly added child within xaml.
<listbox> <listbox.resources> <style targettype="listboxitem"> <setter property="foreground" value="red"/> </style> </listbox.resources> <listboxitem>lbi 1</listboxitem> <listboxitem>lbi 2</listboxitem> </listbox>
Comments
Post a Comment