SilverlightShow: Using the ToolTip control in Silverlight 2 Comments Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples en-us (Emil Stoychev) Argotic Syndication Framework, RE: Using the ToolTip control in Silverlight 2 <p>How can i use the Tooltip style mentioned in App.xaml file to set the style for the tooltip programatically?</p> <p>I defined following in App.xaml file:</p> <p> </p> <p><</p> <p> </p> <p><font color="#a31515" size="2">Style</font><font color="#ff0000" size="2"> x</font><font color="#0000ff" size="2">:</font><font color="#ff0000" size="2">Key</font><font color="#0000ff" size="2">="TooltipFormat"</font><font color="#ff0000" size="2"> TargetType</font></p> <p><font color="#0000ff" size="2">="ToolTip"></font><font color="#a31515" size="2"> <p> </p> <p> </p> <font color="#0000ff" size="2"><</font><font color="#a31515" size="2">Setter</font><font color="#ff0000" size="2"> Property</font><font color="#0000ff" size="2">="Foreground"</font><font color="#ff0000" size="2"> Value</font><font color="#0000ff" size="2">="Red"></</font><font color="#a31515" size="2">Setter</font> <p><font color="#0000ff" size="2">></font><font color="#a31515" size="2"> <p> </p> <p> </p> <font color="#0000ff" size="2"></</font><font color="#a31515" size="2">Style</font><font color="#0000ff" size="2">></font> <p> </p> <p>In the code file i am accessing the style in following way but i get parser error:</p> <font color="#2b91af" size="2"> <p>TextBlock</p> </font><font size="2"> objToolTip = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">TextBlock</font><font size="2">();</font><font size="2"> <p>objToolTip.Text = reader.GetAttribute(</p> <p>objToolTip.TextWrapping =</p> <p>objToolTip.HorizontalAlignment =</p> <p>objToolTip.Width = 200;</p> <p> </p> </font><font color="#a31515" size="2">"toolTip"</font><font size="2">);</font><font color="#2b91af" size="2">TextWrapping</font><font size="2">.Wrap;</font><font color="#2b91af" size="2">HorizontalAlignment</font><font size="2">.Left;</font><font color="#2b91af" size="2">ToolTipService</font><font size="2">.SetToolTip(txtCategory, objToolTip);</font> <p> </p> <p> </p> <p> </p> <p> </p> <p> Parimal</p> </font></p> </font></p> ( Parimal) Wed, 11 Jun 2008 13:47:48 -0500 RE: Using the ToolTip control in Silverlight 2 Brij, <p>check this Silverlight example also: (hover over to get the tooltip)</p><div id="silverlightControlHost" style="width: 150px; height: 190px;"> <object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%"> <param name="source" value=""/> <param name="background" value="white" /> <a href="" style="text-decoration: none;"> <img src="" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </object> <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe> </div><p>Download the source code <a href="">here</a></p> ( emil) Wed, 11 Jun 2008 05:07:17 -0500 RE: Using the ToolTip control in Silverlight 2 <p>Hi brij,</p> <p>Yes, it is possible and actually it is pretty easy. Lets take the example from the article. Instead of an Image control in the ToolTip.Content you can put a TextBlock element and create an event handler for its Loaded event. In the event handler you can make the call the web service to get the data you want to display. To get the idea see the example below:</p> <pre class="code"><span style="color: blue"><</span><span style="color: #a31515">Image </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="turtle" </span><span style="color: red">Source</span><span style="color: blue">="GiantSeaTurtle.jpg" <br /></span><span style="color: red"> Width</span><span style="color: blue">="400" </span><span style="color: red">Height</span><span style="color: blue">="300"> <</span><span style="color: #a31515">ToolTipService.ToolTip</span><span style="color: blue">> <</span><span style="color: #a31515">ToolTip</span><span style="color: blue">> <</span><span style="color: #a31515">ToolTip.Content</span><span style="color: blue">> <</span><span style="color: #a31515">TextBlock </span><span style="color: red">Loaded</span><span style="color: blue">="toolTip_Loaded"></</span><span style="color: #a31515">TextBlock</span><span style="color: blue">> </</span><span style="color: #a31515">ToolTip.Content</span><span style="color: blue">> </</span><span style="color: #a31515">ToolTip</span><span style="color: blue">> </</span><span style="color: #a31515">ToolTipService.ToolTip</span><span style="color: blue">> </</span><span style="color: #a31515">Image</span><span style="color: blue">></span></pre> <pre class="code"><span style="color: blue"><font color="#000000">Code behind<br /><br /><pre><span style="color: blue">private void </span>toolTip_Loaded( <span style="color: blue">object </span>sender, <span style="color: #2b91af">RoutedEventArgs </span>e ) { <span style="color: green">// call the web service to get the desired data </span><span style="color: blue">string </span>data = <span style="color: #a31515">"data received from the web service"</span>; ( ( <span style="color: #2b91af">TextBlock </span>)sender ).Text = data; }</pre> </font></span> <pre class="code"><span style="color: blue"><font color="#000000">The Loaded event will be fired exactly when the ToolTip <br />has to be shown (i.e. when the mouse is over the control).</font></span></pre> <pre class="code"><span style="color: blue"><font color="#000000">Hope this helps</font></span></pre> </pre> ( emil) Wed, 11 Jun 2008 04:46:48 -0500 RE: Using the ToolTip control in Silverlight 2 <p>hi,</p> <p>is it possible to load a tooltip content, through a webservice, if and only if someone hovers over the image; say we are trying to get some data on the mousemove over a datagrid rows, there migth be 10000 rows, and we are intrstd in getting the tooltip content on the fly.</p> <p>regards</p> <p> </p> ( brij) Wed, 11 Jun 2008 03:51:16 -0500