WPF中的ToolTip和Popup疑问

刚开始学习WPF,本来在Winform中可以很好控制的ToolTip,到了WPF中,却变得摸不着头脑,没有Show方法,不能直接指定显示到某个控件,很是烦恼。

虽然ToolTip有IsOpen属性,但是发现IsOpen=true时并没有显示,只能鼠标悬停之后开能显示,于是放弃。

后来找到了Popup,通过设置IsOpen=true可以让Popup显示出来。因为需要指定位置进行显示,于是用到了下面的代码:

 

XAML内容:

<Popup Name="joinPopup" StaysOpen="False" AllowsTransparency="True" PopupAnimation="Slide" Placement="Relative">
<Border Background="White" BorderBrush="Orange" BorderThickness="2" CornerRadius="3" Opacity="0.9" Width="165" Height="32">
<Canvas>
<Image Source="/Data.IMClient;component/Images/Im_Error.png" Stretch="Fill" Width="16" Height="16" Margin="4,5,0,6" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Name="joinPopupTextBlock" Text="2011" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="30,5,0,6"/>
</Canvas>
</Border>
</Popup>

后台代码:

 

代码
Point point = this.comboBoxUserName.TranslatePoint(new Point(0, 0), (UIElement)this.JoinGrid);
this.joinPopupTextBlock.Text = "请您输入帐号后再登录";
this.joinPopup.VerticalOffset = point.Y + this.comboBoxUserName.Height;
this.joinPopup.HorizontalOffset = point.X;
this.joinPopup.IsOpen = true;

其中comBoxUserName是我想要显示Popup相关的控件,joinGrid是comBoxUserName的父容器控件。

 

WPF还在学习阶段,上面如有错误,恳请指正。

posted @ 2010-12-15 15:26  大鼻子  阅读(2480)  评论(2)    收藏  举报