c# wpf - cannot set both DisplayMemberPath and ItemTemplate -


i want add tooltip in listboxitem starts problem when there displaymemberpath. error message said: cannot set both displaymemberpath , itemtemplate. when removed displaymemberpath, tooltip in each list item working. dont want remove displaymemember because need it. how solve problem?

               <listbox x:name="lsttoys" style="{dynamicresource listboxstyle1}"  itemssource="{binding strings}" displaymemberpath="toys" mousedoubleclick="lsttoys_mousedoubleclick">                     <listbox.itemtemplate>                         <datatemplate>                             <textblock text="{binding}" tooltip="here tooltip"/>                         </datatemplate>                     </listbox.itemtemplate>                 </listbox> 

displaymemberpath is, in effect, template single property, shown in textblock. if set:

<listbox x:name="lsttoys" style="{dynamicresource listboxstyle1}"            itemssource="{binding strings}" displaymemberpath="toys"> </listbox> 

it equivalent to:

<listbox x:name="lsttoys" style="{dynamicresource listboxstyle1}"            itemssource="{binding strings}">     <listbox.itemtemplate>         <datatemplate>             <textblock text="{binding toys}"/>         </datatemplate>     </listbox.itemtemplate> </listbox> 

you can remove displaymemberpath path , use value in datatemplate's binding:

<listbox x:name="lsttoys" style="{dynamicresource listboxstyle1}"            itemssource="{binding strings}">     <listbox.itemtemplate>         <datatemplate>             <textblock text="{binding toys}" tooltip="here tooltip!"/>         </datatemplate>     </listbox.itemtemplate> </listbox> 

edit

if want set tooltip keep displaymemberpath, can @ itemcontainerstyle:

<listbox x:name="lsttoys" style="{dynamicresource listboxstyle1}"            itemssource="{binding strings}" displaymemberpath="toys">     <listbox.itemcontainerstyle>         <style targettype="listboxitem">             <setter property="tooltip" value="here's tooltip!"/>         </style>     </listbox.itemcontainerstyle> </listbox> 

i'd advise against it. remember use displaymemberpath stops complex binding in data template.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -