WPF 工具提示(ToolTip)

WPF的工具提示实现方法如下

1:简单的工具提示只需设置元素的ToolTip属性

     example:

<Button Margin="20" Grid.Row="2" ToolTip="This is a button">
another button
</Button>

2:复杂的工具提示需要使用更复杂的嵌套内容设置ToolTip属性

example:

代码
<Window x:Class="grid_Study.MainWindow"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
Title
="MainWindow" Height="350" Width="525" >
<Button Content="my button">
<Button.ToolTip>
<StackPanel>
<TextBlock Margin="3">Image and text</TextBlock>
<Image Source="C:\Users\Public\Pictures\Sample Pictures\baxianhua.jpg" Width="150" Height="150"/>
<TextBlock Margin="3">Image and text</TextBlock>
</StackPanel>
</Button.ToolTip>
</Button>
</Window>

3.工具提示的显示位置:

3.1 相对于鼠标的位置

3.2 相对于元素的侧边

3.3 相对于元素进行偏移

 

4.设置ToolTipService属性

通过ToolTipService属性配置工具提示框显示的延迟时间

posted @ 2010-12-15 16:01  绿茶叶  阅读(4053)  评论(0编辑  收藏  举报