Click here to Skip to main content
15,885,782 members
Articles / MVVM
Tip/Trick

ToolTip for Disabled Element in Silverlight.

Rate me:
Please Sign up or sign in to vote.
4.75/5 (7 votes)
13 Nov 2010CPOL 22K   2   4
ToolTip for Disabled Element in Silverlight

I noticed that there are many conversations departing in Silverlight forums regarding tool tip support for disabled elements in Silverlight. Silverlight program manager also accepts here that having the ToolTip not show on a disabled element is by design. However some folks suggesting mouse enter and mouse leave, and some evoking style modification, etc... But these approaches are not applicable when you develop your Silverlight application in MVVM pattern. Here is the simple approach that helps you to set tooltip for disabled item.


Host a rectangle on top of your element in a grid and bind the visibility property of the Rectangle with IsEnabled property of target element (Make sure that you have BooleanToVisibilityConverter like the one in WPF). And bind your business property with tooltip of the rectangle as well as for your target element if you want to display in enabled state also. And also don’t forget to bind Rectangle Width and Height property with ActualWidth and ActualHeight of Button.


Here is the code.



XML
<Grid Margin="30,0,20,0">
<Button x:Name="MyButton" Content="See My ToolTip when I am in Disabled" IsEnabled="{Binding Path=IsEnabled}"/>
<Rectangle x:Name="toolTipForDiabledButton" Visibility="{Binding Path=IsEnabled, ElementName=AddButton, Converter={StaticResource BoolToVisibilityConverter}}" ToolTipService.ToolTip="{Binding Path=MyToolTip, Mode=TwoWay}" Fill="Transparent"
Width="{Binding Path=ActualWidth, ElementName=AddButton}" Height="{Binding Path=ActualHeight, ElementName=AddButton}">
</Rectangle>
</Grid>


Hope this helps the MVVM folks.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Logitech Engineering & Design (India) Pvt. Ltd.
India India
Venugopal works as a Senior Software Engineer in Logitech Engineering & Design (India) Pvt. Ltd. He hold a Masters in Computer Applications and has 4+ years experience in C#, XAML, Silverlight & WPF.

Venugopal firmly believes "technology is impermanent, change is not"!. While he has strong technical inclination towards MS technologies, he is deeply passionate about pursuing his career in Windows7-WPF and Silverlight Technology.

Venu engages in a wide gamut of temperamental hobbies ranging from making friends, traveling, helping his friends studies. To murmuring songs and watching movies in leisure time.

Comments and Discussions

 
QuestionTwoWay tooltip binding? Pin
mtiede23-Jul-14 10:56
mtiede23-Jul-14 10:56 
SuggestionNice Tip Pin
chanakya3319-Jun-12 8:43
chanakya3319-Jun-12 8:43 
GeneralCheeky :) Pin
Member 54296208-Nov-10 17:06
Member 54296208-Nov-10 17:06 
GeneralReason for my vote of 5 Good one. Pin
PumbaPumba3-Nov-10 4:09
PumbaPumba3-Nov-10 4:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.