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

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 旻

关于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属性为什么没有异常呢?