1、xaml 中实现
<Rectangle x:Name="toolTip" Grid.Column="0" Grid.Row="1" Fill="White" Width="100" Height="100">
<ToolTipService.ToolTip>
<TextBlock>这里是toolTip!</TextBlock>
</ToolTipService.ToolTip>
</Rectangle>
2、c#语言中实现
string tip = "这里是toolTip!";
toolTip.SetValue(ToolTipService.ToolTipProperty, tip);
<!--xaml里面矩形的定义-->
<Rectangle x:Name="toolTip" Grid.Column="0" Grid.Row="1" Fill="White" Width="100" Height="100">
</Rectangle>
3、曲线救国
添加一个Popu控件,并实现两个Mouse事件即可。
<Rectangle x:Name="toolTip" Grid.Column="0" Grid.Row="1" Fill="White" Width="100" Height="100" MouseLeave="toolTip_MouseLeave" MouseMove="toolTip_MouseMove">
</Rectangle>
<Popup x:Name="tip">
<TextBlock Foreground="Red" Text="这里是Popup"/>
<!--<Rectangle Fill="DeepSkyBlue" Width="60" Height="40" />-->
</Popup>
private void toolTip_MouseLeave(object sender, MouseEventArgs e)
{
this.tip.IsOpen = false;
} private void toolTip_MouseMove(object sender, MouseEventArgs e)
{
this.tip.IsOpen = true;
this.tip.HorizontalOffset = e.GetPosition(null).X + ;
this.tip.VerticalOffset = e.GetPosition(null).Y - ;
}