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

推荐订阅源

The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
V
Visual Studio Blog
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
Vercel News
Vercel News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
The Cloudflare Blog
宝玉的分享
宝玉的分享
V
V2EX
Microsoft Azure Blog
Microsoft Azure 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自定义模版后不能显示内容的问题——Co...
· 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属性为什么没有异常呢?