Silverlight DescriptionViewer prevent Tooltip to disappear on click -


the silverlight 4 descriptionviewer control displays description in tooltip:

the syntax pretty easy: add namespace xmlns:datainput="clr-namespace:system.windows.controls;assembly=system.windows.controls.data.input" , following xaml usercontrol:

<datainput:descriptionviewer description="some hints on user input etc." /> 

unfortunately, users click on displayed icon (since hovers default) instantly closes tooltip (the actual , information). worse, when click after hovering, tooltip won't appear @ all, user might think icon has no function @ all.

i'd prevent closing tooltip on click (just close on "mouse out"), better clicking should force tooltip show (skipping usual timeout before shown).

it seems harder though, since there no onclick event , mouseleftbuttondown seems not fire @ all. tried override descriptionviewer control no luck finding appropriate methods override.

can help? thank you!

this has nothing descriptionviewer, behavior of tooltip. tooltip disappear once mouse click. in case might want write own tooltip.

i think when click on descriptionviewer icon, there should new window open more detailed page. user wouldn't confused.

update:

you can achieve defining attached property. basically, attach property button inside descriptionviewer. when button's click event fired, find tooltip underneath button , set isopen ture. need handle mouseleave event hide tooltip once mouse's away.

this how attached property defined.

public static class buttonattachedproperties { public static bool getopentooltip(dependencyobject obj) { return (bool)obj.getvalue(opentooltipproperty); }

public static void setopentooltip(dependencyobject obj, bool value) {     obj.setvalue(opentooltipproperty, value); }  public static readonly dependencyproperty opentooltipproperty =     dependencyproperty.registerattached("opentooltip", typeof(bool), typeof(buttonattachedproperties), new propertymetadata(false, callback));   private static void callback(dependencyobject d, dependencypropertychangedeventargs e) {     var button = d button;      if (button == null || !(bool)e.newvalue) return;      button.click += (s, e1) =>     {         var tooltip = button.findname("mytooltip") tooltip;          if (tooltip != null)         {             tooltip.placementtarget = button;             tooltip.isopen = true;               }     };      button.mouseleave += (s, e2) =>     {         var tooltip = button.findname("mytooltip") tooltip;          if (tooltip != null)             tooltip.isopen = false;     }; } 

}

then in descriptionviewer's style, attach property button. need name tooltip in order able find using findname in attach property class.

                        <border borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" height="{templatebinding height}" padding="{templatebinding padding}" width="{templatebinding width}">                             <button x:name="descriptioncontent" local:buttonattachedproperties.opentooltip="true" borderbrush="#ffffffff" borderthickness="1" background="#00000000" horizontalalignment="{templatebinding horizontalcontentalignment}" istabstop="false" padding="1" template="{templatebinding glyphtemplate}" visibility="collapsed" verticalalignment="{templatebinding verticalcontentalignment}">                                 <tooltipservice.tooltip>                                     <tooltip x:name="mytooltip" content="{templatebinding description}" placementtarget="{binding relativesource={relativesource templatedparent}}" style="{templatebinding tooltipstyle}"/>                                 </tooltipservice.tooltip>                             </button>                         </border> 

hope helps. :)


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -