Archive for the 'Silverlight' Category

Silverlight 2: Styling the control ToolTip

Working with control tooltip in Silverlight 2 (Beta 2) can be a bit tricky. As of Beta 2, it’s not as straight forward as it is in WPF. In this post I’ll show an easy way to create and customize tooltip style of Silverlight control.

At the very basic, you can add a default tooltip to Silverlight control by nesting ToolTipService.ToolTip dependency property in the XAML. What you’ll get is the default tooltip that looks like this.

Default Silverlight control tooltip

In this example, I’ll use the WPF tooltip style created by Lee Brimelow. I change it a little to make it work on Silverlight. I add this style to my App.xaml so that it’s available throughout the application. Name it “ToolTipStyle”.

Styling the tooltip in App.xaml

Next, in the control, I just set the style to "{StaticResource ToolTipStyle}" and also set the text content that will show up in the tooltip box.

Setting control tooltip

And the target control will get its tooltip style set.

Tooltip style customized

Note here is the use of ContentPresenter in the style template. ContentPresenter allows you to customize the look of tooltip content even further. Let’s stay I want to put a button in my tooltip.

UIElement as tooltip content

And here it is! The button is not clickable though :).

2 Comments »

Teera on June 15th 2008 in Silverlight, Software Development, .NET

Silverlight 2: Iterating System.Windows.Media.Colors with Reflection and Linq

I ran into a problem of creating color panel in a Silverlight project I’m working on. This color panel initially have to show system named colors that are static properties of System.Windows.Media.Colors class.

Silverlight 2: Iterating System.Windows.Media.Colors with reflection and Linq 1

After some thoughts, I didn’t find any other solutions but to go down the Reflection path. Also, to make the colors in the panel arranged harmoniously they needed to be sorted before adding to the panel.

Silverlight 2: Iterating System.Windows.Media.Colors with reflection and Linq 2

This method can certainly be improved with the combination of Reflection and Linq.

Silverlight 2: Iterating System.Windows.Media.Colors with reflection and Linq 3

Half the code is gone. Looks much better now :)