Reputation: 984
I have a basic TextBlock
<TextBlock x:Name="myTextBlock" Text="textOfThisTextblock" ToolTip="..."/>
and I want to set the Tooltip
to the exact same string as the Text
of the TextBlock
. How can I do that automatically?
So I don't wanna set it manually if I change the Text
.
I tried
ToolTip="{Binding Path=myTextBlock.Text}"
but this didn't work.
Upvotes: 0
Views: 90
Reputation: 35681
use RelativeSource Self
<TextBlock x:Name="myTextBlock"
Text="textOfThisTextblock"
ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Mode=Self}}"/>
or ElementName
<TextBlock x:Name="myTextBlock"
Text="textOfThisTextblock"
ToolTip="{Binding Path=Text, ElementName=myTextBlock}"/>
or you can do it for all TextBlocks using Style:
<Style TargetType="TextBlock">
<Setter Property="ToolTip"
Value="{Binding Path=Text, RelativeSource={RelativeSource Mode=Self}}" />
</Style>
Upvotes: 2