Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在自定义控件上使用RelativeSource绑定工具提示内容的正确方法是什么?_C#_Wpf_Xaml_Binding_Relativesource - Fatal编程技术网

C# 在自定义控件上使用RelativeSource绑定工具提示内容的正确方法是什么?

C# 在自定义控件上使用RelativeSource绑定工具提示内容的正确方法是什么?,c#,wpf,xaml,binding,relativesource,C#,Wpf,Xaml,Binding,Relativesource,按照所需的“—— 这是复制问题的“自定义控件” XAML: <TextBlock x:Class="FooTips.FooTipControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:l="clr-namespace:FooTips"

按照所需的“——

这是复制问题的“自定义控件”

XAML:

<TextBlock
    x:Class="FooTips.FooTipControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:l="clr-namespace:FooTips"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    d:DesignHeight="300" d:DesignWidth="300" mc:Ignorable="d"
    Text="{Binding FooTipText, RelativeSource={RelativeSource Self}}">
    <TextBlock.ToolTip>
        <ToolTip Content="{Binding FooTipText, RelativeSource={RelativeSource AncestorType={x:Type l:FooTipControl}, Mode=FindAncestor}}" />
    </TextBlock.ToolTip>
</TextBlock>
如何调整工具提示绑定,使其在控件属性上拾取?

此功能:

<TextBlock x:Class="FooTips.FooTipControl"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:l="clr-namespace:FooTips"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            d:DesignHeight="300" d:DesignWidth="300" mc:Ignorable="d"
            Text="{Binding FooTipText, RelativeSource={RelativeSource Self}}"
            ToolTip="{Binding FooTipText, RelativeSource={RelativeSource Self}}">
</TextBlock>

……这也是:

<TextBlock.ToolTip>
    <ToolTip Content="{Binding PlacementTarget.FooTipText, RelativeSource={RelativeSource Self}}" />
</TextBlock.ToolTip>

这项工作:

<TextBlock x:Class="FooTips.FooTipControl"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:l="clr-namespace:FooTips"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            d:DesignHeight="300" d:DesignWidth="300" mc:Ignorable="d"
            Text="{Binding FooTipText, RelativeSource={RelativeSource Self}}"
            ToolTip="{Binding FooTipText, RelativeSource={RelativeSource Self}}">
</TextBlock>

……这也是:

<TextBlock.ToolTip>
    <ToolTip Content="{Binding PlacementTarget.FooTipText, RelativeSource={RelativeSource Self}}" />
</TextBlock.ToolTip>