What's the difference between ItemTemplate and ItemContainerStyle in a WPF ListBox? -


in wpf listbox, i'm confused these 2 notions: itemtemplate , itemcontainerstyle can explain me more?

the itemtemplate styling how content of data item appears. use bind data fields, format display strings, , forth. determines how data presented.

the itemcontainerstyle styling container of data item. in list box, listboxitem. styling here affects things selection behavior or background color. determines style , ux of display.

the msdn page itemcontainerstyle, linked above, has pretty example showing differences:

 <!--use itemtemplate set datatemplate define       visualization of data objects. datatemplate       specifies each data object appears proriity       , taskname on top of silver ellipse.-->   <itemscontrol.itemtemplate>     <datatemplate>       <datatemplate.resources>         <style targettype="textblock">           <setter property="fontsize" value="18"/>           <setter property="horizontalalignment" value="center"/>         </style>       </datatemplate.resources>       <grid>         <ellipse fill="silver"/>         <stackpanel>           <textblock margin="3,3,3,0"                      text="{binding path=priority}"/>           <textblock margin="3,0,3,7"                      text="{binding path=taskname}"/>         </stackpanel>       </grid>     </datatemplate>   </itemscontrol.itemtemplate>   <!--use itemcontainerstyle property specify appearance       of element contains data. itemcontainerstyle       gives each item container margin , width. there       trigger sets tooltip shows description of       data object when mouse hovers on item container.-->   <itemscontrol.itemcontainerstyle>     <style>       <setter property="control.width" value="100"/>       <setter property="control.margin" value="5"/>       <style.triggers>         <trigger property="control.ismouseover" value="true">           <setter property="control.tooltip"                   value="{binding relativesource={x:static relativesource.self},                           path=content.description}"/>         </trigger>       </style.triggers>     </style>   </itemscontrol.itemcontainerstyle> 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -