微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

 Collapse
<Grid Margin="30,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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐