Thursday, August 16, 2007

Creating custom ToolTip using XAML in WPF applications


Some of you know that creating a custom tooltip in non-standard ui applications is a real headic, but with using WPF classes and XAML you can create a custom tooltip (such as Office 2007 tooltips or any other style you want) in just a minute as follow

1. On VS code name Orcas, or VS 2005 with WPF extension installed (you can get the extensions from
Here), and create project with the "WPF Application" template

Add button to the main window

2. In the main window (Window1.xaml) drop down the control that the tooltip will apply to

Create new project window

3. Inside the "Button" tag in the XAML view, and insert a new "Button.Tooltip" tag that contains a "StackPanel" tag (which will serve as a container for the our custom tooltip) and insert the following tags (which represent controls in the System.Windows.Controls namespace) inside it:
·Label
·TextBlock
·Line
·StackPanel which contains Image and Label tags
as shown in the picture

<XAML code

Note that you must edit the source attribute of the image control to an existing resource in your project

4. Finally, run the project and see the result

<<Final Window

As you see we create this tooltip in minutes, and you can customize it using any controls available in the "System.Windows.Controls" namespace or any cusotm controls inherit from it