WPF,ToolTip工具提示的位置怎么没对啊

dgfm4 2014-04-26 11:21:25

<Window x:Class="WPF1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF1"
Title="MainWindow" Height="550" Width="825">
<Grid>
<Ellipse Height="25" Width="50" Fill="Gray" HorizontalAlignment="Left">
<Ellipse.ToolTip>
<ToolTip Placement="Right" PlacementTarget="{Binding ElementName=Button2}" HorizontalOffset="50" VerticalOffset="-70" HasDropShadow="false">
张三
</ToolTip>
</Ellipse.ToolTip>
</Ellipse>
<Button Name="Button2" Content="Button2" HorizontalAlignment="Left" Margin="130,354,0,0" VerticalAlignment="Top" Width="74"/>
</Grid>
</Window>



上面的代码中,设置了ToolTip 的Placement属性值为Right,PlacementTarget值为Button2,然后又设置了HorizontalOffset和VerticalOffset值。那当鼠标移到Ellipse 上时,提示框的弹出位置就应该是以Button2的位置来计算的吧。
可是,为什么结果提示框的弹出位置还是以Ellipse的位置来进行计算的呢?
...全文
474 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lbwxly2012 2014-05-07
  • 打赏
  • 举报
回复
MSDN上说的是PlacementTarget是表示ToolTip的logic parent. 这里已经通过设置<Ellipse.ToolTip>属性将ToolTip的logic parent设置为了Ellipse,因此我估计在呈现ToolTip的时候应该不会再去看PlacementTarget的值了。
dgfm4 2014-05-07
  • 打赏
  • 举报
回复
设置了PlacementTarget值为Button2的啊,所以Button2就是目标对象啊,HorizontalOffset="50" VerticalOffset="-70"这些值都应该以Button2的位置来计算啊
欢乐的小猪 2014-05-06
  • 打赏
  • 举报
回复
位置很对啊 。 Placement="Right" 相对Ellipse的右侧 HorizontalOffset="50" 相对Ellipse的右侧的x初始位移为50 VerticalOffset="-70" 相对Ellipse的右侧的y初始位移为-70
dgfm4 2014-05-06
  • 打赏
  • 举报
回复
引用 9 楼 hbu_pig 的回复:
设置了PlacementTarget值为Button2的啊,所以Button2就是目标对象啊,HorizontalOffset="50" VerticalOffset="-70"这些值都应该以Button2的位置来计算啊
dgfm4 2014-05-06
  • 打赏
  • 举报
回复
有人知道吗??
欢乐的小猪 2014-05-06
  • 打赏
  • 举报
回复
我看了吖。<Ellipse.ToolTip>说明是Ellipse的ToolTip吖,以下是我copy msdn的一段话。 详见http://msdn.microsoft.com/zh-cn/library/vstudio/system.windows.controls.tooltip(v=vs.85).aspx 示例 -------------------------------------------------------------------------------- This example shows how to define a tooltip control for a TextBox element. The following example shows how to define a tooltip by assigning text to the ToolTip property. XAML <TextBox HorizontalAlignment="Left">TextBox with ToolTip <TextBox.ToolTip> <TextBlock>Useful information goes here.</TextBlock> </TextBox.ToolTip> </TextBox>
dgfm4 2014-05-06
  • 打赏
  • 举报
回复
引用 7 楼 hbu_pig 的回复:
位置很对啊 。 Placement="Right" 相对Ellipse的右侧 HorizontalOffset="50" 相对Ellipse的右侧的x初始位移为50 VerticalOffset="-70" 相对Ellipse的右侧的y初始位移为-70
你是没有看我的问题吧。 设置了PlacementTarget值为Button2,提示框的弹出位置就应该是以Button2的位置来计算的吧。 可是,为什么结果提示框的弹出位置还是以Ellipse的位置来进行计算的呢?
dgfm4 2014-04-28
  • 打赏
  • 举报
回复
有人知道吗??
exception92 2014-04-27
  • 打赏
  • 举报
回复

PlacementTarget="{Binding ElementName=Button2}"
你应该 再指定一下 Path吧?
dgfm4 2014-04-27
  • 打赏
  • 举报
回复
有人知道吗?

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧