Tuesday, February 01, 2011

Multi line ToolTip in Silverlight App

2 days back I came across a requirement in my Silverlight 4 project where I need to display a multiline tooltip on my control… if it is just a tooltip then its very simple requirement. we can just use

ToolTipService.ToolTip="tool tip text”.

or we can also bind it to some object and set the tool tip text to that object. e.g.

ToolTipService.ToolTip="{Binding ActivityToolTip}"

but what if I want to display a tool tip which contains more than 1 line ?

one can simply say user “\n” in text, but there is problem. if you going to assign tooltip text in your XAML then you can not use “\n” in your XAML code. it will give you error. if you binding it and going to assign tool tip form your C# code then you can use “\n” but not in XAML code.

while searching I got a nice solution on MSDN forum which worked for me and now I can add multiline tooltip from my XAML code itself.

you can use 
 to define the new line character. so code will be like this

ToolTipService.ToolTip = “ ToolTip Line 1 
 ToolTip Line 2 
 ToolTip Line 3”

and the out for above will be tooltip like -

ToolTip Line 1

ToolTip Line 2

ToolTip Line 3