可是在下面两篇提问中可以发现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>
<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;
}
}
}
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 >
还有没有什么更好的解决方案呢?
< 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 >