微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight入门学习29

原文地址: http://www.dingos.cn/index.php?topic=2000.0

第二十九章   Silverlight 控件添加 工具提示

Silverlight 提供了一个名为“ ToolTipService ”的控件用 于为 Silverlight 控件显示工具提示。这个类可以附着在 Silverlight 中的大多数 UI 元素上用于显示工具提示

简 单的文本提示

下面的示例代码显示如何为一个按钮控件添加工具提示

< Button Width ="60" Height ="20" Content ="My Button">

    < ToolTipService.ToolTip >

        < ToolTip Content ="This is tool tip for Button"></ ToolTip >

    </ ToolTipService.ToolTip >

</ Button >

看下面的示例用于为文本框控件设置工具提示

< TextBlock Width ="60" Height ="20" Text ="My Text">

    < ToolTipService.ToolTip >

        < ToolTip Content ="This is tool tip for TextBlock"></ ToolTip >

    </ ToolTipService.ToolTip >

</ TextBlock >

显 示富 UI 元素提示

Silverlight 在工具提示支持 UI 元素,使用户得到更好的体验。在工具 提示时可以使用更多的 UI 元素。看下面显示的例子

提示工具中显示图像

示例代码显示 Silverlight 中如何显示图像工具提示

< TextBox Width ="60" Height ="20" Text ="My Text">

    < ToolTipService.ToolTip >

        < Image Source ="http://www.dotnetspider.com/images/spiderlogo.jpg" >

        </ Image >

    </ ToolTipService.ToolTip >

</ TextBox >

为整个 Silverlight 控件进行提示

可以为整个 Silverlight 工具设置提示。看如下代码

< UserControl x : Class ="MySilverlightApp.Page"

     xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     xmlns : x ="http://schemas.microsoft.com/winfx/2006/xaml"

     Width ="400" Height ="300">

    < StackPanel x : Name ="LayoutRoot" Background ="White">

        < ToolTipService.ToolTip >

            < ToolTip Content ="This is tool tip for entire control"></ ToolTip >

        </ ToolTipService.ToolTip >

    </ StackPanel >

</ UserControl >

编 程方式设置工具提示

可以从后台代码文件设置或改变工具提示。下面例子显示如何从后台代码文件为按钮控件设置文本提 示:

ToolTipService .SetToolTip(MyButton,"This is new tooltip" );

@H_377_502@

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐