wpf - 对多个文本框重复使用工具提示

标签 wpf data-binding resources tooltip

我应该在工具提示资源的 Text 属性的值中写入什么,以便它动态显示每个文本 block 的文本?

 <StackPanel x:Name="root">
    <StackPanel.Resources>
        <ResourceDictionary>

            <ToolTip x:Key="tooltiptemplate">
                <TextBlock Background="LightBlue" TextTrimming="WordEllipsis" Text="?????"/>
            </ToolTip> 

        </ResourceDictionary>
    </StackPanel.Resources>

    <TextBlock Text="Mickel" ToolTip="{StaticResource tooltiptemplate}"/>
    <TextBlock Text="Kim" ToolTip="{StaticResource tooltiptemplate}"/>
    <TextBlock Text="Jenny" ToolTip="{StaticResource tooltiptemplate}"/>
</StackPanel>

最佳答案

{Binding PlacementTarget.Text, RelativeSource={RelativeSource AncestorType={x:Type ToolTip}}}

关于wpf - 对多个文本框重复使用工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4304515/

相关文章:

c# - RelayCommand 不会在按钮单击时执行

c# - WPF 二维数组绑定(bind)和上下文菜单

c# - WPF TextBlock 文本绑定(bind)

android - 找不到与给定名称匹配的资源

wpf - 将 UserControl 的依赖属性值传输到其中的 Control

c# - 来自 System.Windows.Forms 的 AccessViolationException,在 WPF 中使用 WinFormsHost

c++ - fatal error CVT1100 : duplicate resource. 类型 :ICON, 名称 :1 (C++, Visual Studio C++ 2010)

php mysql 查询资源 null 错误

c# - 直接显示 : display graph result onto wpf window

C# 将 html 文档与 TreeView 绑定(bind)