惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 旻

关于WPF性能 Sysinternals 实用工具:进程 又关注了一下WPF/SL的混淆问题 随手日记 0525 随手日记 0524 客户端类型软件与用户规模表 2D MatrixTransform的原理 随手日记 0510 将数字世界和真实世界结合的视频。MIT牛人。 WPF 的资源 Ideum的100英寸触摸屏支持50个触摸点 微软多点触摸鼠标视频图片荟萃 [转]win7多点触控的十万个为什么 监听所有的依赖属性 搜集几个多点触摸的视频 Public Computer——未来电脑的新分支,多点触摸的新舞台。 限制WPF Text中的输入字符和长度 6.4 流水账-拖拽,又见拖拽 流水账 5.26 Dell XT2被大卸八块
7.10 WPF 流水账 Tooltip自定义模版后不能显示内容的问题——ControlTemplate的秘密 - 旻
· 2009-07-10 · via 博客园 - 旻

ControlTemplate 是我使用最早的Template。昨天居然在小河沟里翻船了。

问题:

手写了一个ToolTip的Template,结果无论如何也显示不出内容,ToolTip不能用Snoop调,急死我了。

<Image Style="{StaticResource ImageStyle}" Stretch="Fill"

                               ToolTipService.InitialShowDelay="0"

                               ToolTipService.ShowDuration="10000"

                               >

                            <Image.Resources>

                                <Style x:Key="tooltip" TargetType="ToolTip">

                                    <Setter Property="Template">

                                        <Setter.Value>

                                            <ControlTemplate >

                                                <Border x:Name="grid1">

                                                    <ContentPresenter></ContentPresenter>

                                                </Border>

                                            </ControlTemplate>

                                        </Setter.Value>

                                    </Setter>

                                </Style>

                            </Image.Resources>

                            <Image.ToolTip>

                                <ToolTip x:Name="nametip"  Style="{StaticResource tooltip}" >

                                    <StackPanel>

                                            <TextBlock x:Name="nickname" Text="{Binding Path=Name, Mode=OneWay}" />

                                        </StackPanel>

                                </ToolTip>

                            </Image.ToolTip>

                        </Image>

简单得不能再简单了.可是文字偏偏怎么也显示不出来.

最后发现

image

模版定义中少了这样的语句.

分析原因:

模版的中定义内容显示的部分是<ContentPresenter/>。它会寻找控件Content的属性,如果不指定ControlTemplate的“TargetType”,他会将控件当做“Control”类型,但是Control没有Content属性,所以内容显示不出来。

结论:

在模版中是ContentPresenter的时候一定要指定ControlTemplate的TargetType属性。

疑惑:

既然ContentPresenter找不到Content属性为什么没有异常呢?