【发布时间】:2020-09-14 19:32:47
【问题描述】:
我尝试以这种方式将ToolTip 文本绑定到UserControl:
<Grid.ToolTip>
<TextBlock
Text="{
Binding Path=InfoTT,
RelativeSource={
RelativeSource Mode=FindAncestor,
AncestorType={x:Type UserControl}
}
}" />
</Grid.ToolTip>
它不起作用,Tooltip 是空的,在日志中,我看到了:
System.Windows.Data 错误:4:无法找到与引用“RelativeSource FindAncestor,AncestorType='System.Windows.Controls.UserControl',AncestorLevel='1''的绑定源。绑定表达式:路径=InfoTT;数据项=空;目标元素是'TextBlock'(名称='');目标属性是“文本”(类型“字符串”)*
但是当我这样做时:
<Grid
ToolTip="{
Binding Path=InfoTT,
RelativeSource={
RelativeSource Mode=FindAncestor,
AncestorType={x:Type UserControl}
}
}">
</Grid>
成功了。谁能解释为什么第一种方法不起作用?
【问题讨论】:
-
我已经编辑了我的答案以提供一些解决方案。
标签: wpf xaml data-binding