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
Post a Comment