SIGN UP MEMBER LOGIN:    
ARTICLE

Creating ToolTip in Silverlight

Posted by Vishal Nayan Articles | Silverlight with C# February 03, 2011
Silverlight has a flexible model for tooltips (those infamous yellow boxes that pop up when we hover over something interesting). Because tooltips in Silverlight are content controls, we can place virtually anything inside a tooltip.
Reader Level:
Download Files:
 

Introduction:

Silverlight has a flexible model for tooltips (those infamous yellow boxes that pop up when we hover over something interesting). Because tooltips in Silverlight are content controls, we can place virtually anything inside a tooltip.

So let us try creating a customized tooltip.

Step 1: Create a new Silverlight application and name is "ToolTip"

Step 2: Open main.xaml

Step 3: The simplest example is a text-only tooltip. We can create a text-only tooltip by setting theToolTipService.ToolTip property on another element,


<Grid x:Name="LayoutRoot">
        <Button ToolTipService.ToolTip="This is my tooltip"
                Margin="3" Padding="5" HorizontalAlignment="Center"
                 Width="200"  Height="30"               
                Content="I have a tooltip"></Button>
</Grid>

Press F5 and see the result;

tooltip1.gif

Step 4: Now let us customize it.

If we want to supply more ambitious tooltip content, such as a combination of nested elements, we need to break the ToolTipService.ToolTip

  <Button Content="I have a fancy tooltip" Padding="10" Margin`="3" HorizontalAlignment="Center"
                 Width="200"  Height="40">
            <ToolTipService.ToolTip>
                <ToolTip Background="DarkRed" Foreground="White">
                    <StackPanel>
                        <TextBlock Margin="3" Text="Image and text"></TextBlock>
                        <Image Source="happyface.jpg"></Image>
                        <TextBlock Margin="3" Text="Image and text"></TextBlock>
                    </StackPanel>
                </ToolTip>
            </ToolTipService.ToolTip>
        </Button>

tooltip2.gif

If you give name to you tooltip, then from code behind we can control its behavior like IsEnabled or disable.

Hope you liked this basic introduction to tooltip.

Cheers.
 

Login to add your contents and source code to this article
share this article :
post comment
 

Hi, I have datagrid celll which have data more than two line, when i display that data in tooltip it goes beyond screen and all data not able to display. I want to display data in multiple line(should split). and tooltip height and width should auto. Could you please tell me workaround for this issue.

Posted by dipti jadhav May 30, 2011

Thanks Sapna , although its a very basic explanation , but sometimes we need it .

Posted by Vishal Nayan Feb 04, 2011

Very nice article Vishal!!!

Posted by Sapna Feb 03, 2011
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Gauge for SharePoint
Become a Sponsor