#377 – 通过将ToolTip定义为资源对其进行重用(Reuse Tooltips by Defining Them as Resources)
2016-10-27 11:26
387 查看
因为提示工具是一个Tooltip 控件的实例,隐藏你可以通过资源字典创建提示控件并重用他们。
下面是一个用绑定数据显示提示控件的例子:
首先定义资源,
然后我们在TextBox 中使用它,
下面是效果图:
使用同样的代码创建提示信息,但是每个Textbox的提示信息都是各自的。
原文地址:https://wpf.2000things.com/2011/09/01/377-reuse-tooltips-by-defining-them-as-resources/
下面是一个用绑定数据显示提示控件的例子:
首先定义资源,
<Window.Resources> <!-- Standard tooltip for TextBox controls, displays Text property of parent control in a TextBlock --> <ToolTip x:Key="textBlockTooltip" DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}"> <StackPanel> <Label FontWeight="Bold" Content="Full Text"/> <TextBlock Text="{Binding Text}" TextWrapping="Wrap" Width="200"/> </StackPanel> </ToolTip> </Window.Resources>
然后我们在TextBox 中使用它,
<TextBox Text="Now is the winter of our discontent etc" Width="100" Margin="10" ToolTip="{StaticResource textBlockTooltip}"/> <TextBox Text="All the world's a stage etc" Width="100" Margin="10" ToolTip="{StaticResource textBlockTooltip}"/>
下面是效果图:
使用同样的代码创建提示信息,但是每个Textbox的提示信息都是各自的。
原文地址:https://wpf.2000things.com/2011/09/01/377-reuse-tooltips-by-defining-them-as-resources/
相关文章推荐
- Two informative resources: Tooltips and CSS tips
- 创建数据库后,怎样可以对其原始定义进行更改?
- 在非web环境下,直接用java命令行运行程序时,对于通过getResources找不到jar包中的资源和目录的解决方法
- 通过AS文件来自定义flex中的组件。
- 搜索引擎的相关搜索(基于struts2框架通过关键字与后台的xml资源进行匹配实现)
- 通过向父亲窗口发送消息,要求其他窗口对其进行销毁
- 设计三角形类,通过增加构造函数,使对象在定义时能够进行初始化2
- 一步一步教你使用AgileEAS.NET基础类库进行应用开发-基础篇-通过SQL实现特殊业务
- 一步一步教你使用AgileEAS.NET基础类库进行应用开发-基础篇-涉及的数据定义
- 五周任务一:设计三角形类,通过增加构造函数,使对象在定义时能够进行初始化
- .NET中通过垃圾收集器(GC)对资源进行主动释放示例
- web developer tips (46):使用Web Deployment Tool进行Web部署迁移
- 通过native2ascii命令将中文资源文件进行编码转换
- 一步一步教你使用AgileEAS.NET基础类库进行应用开发-基础篇-通过SQL实现特殊业务
- 通过 Visual Studio 对 SQL Server 中的存储过程设置断点并进入存储过程对其进行调试
- Two informative resources: Tooltips and CSS tips
- ExtJs是通过Ext.ToolTip和Ext.QuickTips两个组件来实现浮动提示功能的
- web developer tips (46):使用Web Deployment Tool进行Web部署迁移
- 未能找到任何适合于指定的区域性或非特定区域性的资源。请确保在编译时已将“定型测试.Frm.resources”正确嵌入或链接到程序集“定型测试”,或者确保所有需要的附属程序集都可加载并已进行了完全签名
- 设计三角形类,通过增加构造函数,是对象在定义是能够进行初始化