WPF Tooltip binding and open programatically does not work -


i have custom tooltip icon has content bound datacontext. need open tooltop on mouse hover on click event. used following code

<image source="/mainui;component\images\home\tooltip_info.png"         width="24" height="24" stretch="fill" horizontalalignment="right"         name="imagetooltip"        margin="0,0,0,0" mouseup="imagetooltip_mouseup" mouseleave="imagetooltip_mouseleave">     <image.tooltip>         <tooltip borderbrush="transparent" background="transparent" horizontaloffset="-142">             <textblock textwrapping="wrapwithoverflow"                         style="{staticresource excalfont-msfd300}"                         fontsize="14" text="{binding tips}"                         width="300" padding="15,15,15,15">                 <textblock.background>                     <imagebrush imagesource="images\home\popupbox.png" />                 </textblock.background>             </textblock>         </tooltip>     </image.tooltip> </image> 

code behind:

private void imagetooltip_mouseup(object sender, mousebuttoneventargs e) {     ((tooltip)((frameworkelement)sender).tooltip).isopen = true; }  private void imagetooltip_mouseleave(object sender, mouseeventargs e) {     ((tooltip)((frameworkelement)sender).tooltip).isopen = false; } 

now issue on mouse opens tooltip not bind text. working fine if using static text instead of binding. doing wrong?

in case mouse hover on icon works fine , shows content too. thereafter everytime mouse click shows tooltip content. not sure why mouse click not work initially. –

tooltip not part of visualtree. problem similar problem have described here: relativesource binding tooltip or contextmenu

one option solve problem this:

   <image source="/mainui;component\images\home\tooltip_info.png"     width="24" height="24" stretch="fill" horizontalalignment="left"     name="imagetooltip"    margin="0,0,0,0" mouseup="imagetooltip_mouseup" mouseleave="imagetooltip_mouseleave" tag="{binding datacontext,relativesource={relativesource mode=self}}">         <image.tooltip>             <tooltip borderbrush="transparent" background="transparent" horizontaloffset="-142" >                 <textblock textwrapping="wrapwithoverflow"                     fontsize="14" text="{binding placementtarget.tag.tips,          relativesource={relativesource mode=findancestor,ancestortype=tooltip}}"                    width="300" padding="15,15,15,15">                      <textblock.background>                         <imagebrush imagesource="images\home\popupbox.png" />                      </textblock.background>                 </textblock>             </tooltip>         </image.tooltip>     </image> 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -