• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ueqt
博客园    首页    新随笔    联系   管理    订阅  订阅

Silverlight的Tooltip当控件Disable时不显示的问题

在WPF中有ToolTipService.ShowOnDisabled="True"这样的附加属性可以完成这个实现
可是在下面两篇提问中可以发现silverlight中缺乏这样的实现
http://silverlight.net/forums/t/52753.aspx
https://silverlight.net/forums/p/119934/270379.aspx
但是这个对用户体验又是极其重要的,codeplex上有个扩展tooltipservice的项目,可是也并未涉及到这个问题
http://tooltipservice.codeplex.com/

例如 xaml
Code
<UserControl x:Class="Silverlight.Tester.Test"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width
="400" Height="300">
    
<Grid x:Name="LayoutRoot" Background="White">
        
<Button Content="test" Click="Button_Click">
            
<ToolTipService.ToolTip>
                
<TextBlock Text="aaaa"></TextBlock>
            
</ToolTipService.ToolTip>
        
</Button>
    
</Grid>
</UserControl>

code-behind
Code


namespace Silverlight.Tester
{
    
public partial class Test : UserControl
    
{
        
public Test()
        
{
            InitializeComponent();
        }


        
private void Button_Click(object sender, RoutedEventArgs e)
        
{
            ((Button)sender).IsEnabled 
= false;
        }

    }

}


这样当点击了按钮时是不会再显示tooltip了

有一种不怎么有美感的解决方式就是,在要显示tooltip的控件上加一个透明的rectangle,然后在这个rectangle上放置原来要在控件上放的tooltip
这样确实可以显示了
                <Grid>
                    
<Grid.ColumnDefinitions>
                        
<ColumnDefinition Width="*"></ColumnDefinition>
                    
</Grid.ColumnDefinitions>
                    
<Grid.RowDefinitions>
                        
<RowDefinition Height="*"></RowDefinition>
                    
</Grid.RowDefinitions>
                    
<Button Grid.Row="0" Grid.Column="0" x:Name="testButton" Content="test" IsEnabled="False" >
                    
                    
</Button>
                    
<Rectangle Fill="Transparent" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ToolTipService.ToolTip="test">
                        
                    
</Rectangle>
                
</Grid>
还有没有什么更好的解决方案呢?

posted @ 2009-08-26 13:39  ueqt  阅读(473)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3