Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text block , Inside the textblock text is there . I want to bind the text value in tooltip. Below code I have tried .This is working . But How can I bind text value to tooltip without repeating .

What I have tried:

<TextBlock Grid.Column="0"
                               VerticalAlignment="Center"
                               FontFamily="{DynamicResource DefaultFont}"
							   Foreground="{Binding HeaderTextBrush,ElementName=rndPanel}"
							   FontSize="15"
                               FontWeight="Bold"
                               Width="450"
                               ToolTip="{x:Static LibraryView:StringResources.L_AddNewLibraryWindow_SelectCompounds}"
                               Text="{x:Static LibraryView:StringResources.L_AddNewLibraryWindow_SelectCompounds}"
                               HorizontalAlignment="Left">
                    </TextBlock>
Posted
Updated 14-Oct-21 2:48am

1 solution

You want to have the same value for Text and Tooltip?
Then you have to bind the ToolTip Property to the Text Property of your TextBlock.
XAML
<TextBlock 
    Name="MyTextBlock" 
    Text="{Binding MyProperty}"
    ToolTip="{Binding ElementName=MyTextBlock, Path=Text}">
</TextBlock>

Especially for you it must be:
XAML
<TextBlock Name= "MyTextBlock"
           Grid.Column="0"
		   VerticalAlignment="Center"
		   FontFamily="{DynamicResource DefaultFont}"
		   Foreground="{Binding HeaderTextBrush,ElementName=rndPanel}"
		   FontSize="15"
		   FontWeight="Bold"
		   Width="450"
		   ToolTip="{Binding ElementName=MyTextBlock, Path=Text}"
		   Text="{x:Static LibraryView:StringResources.L_AddNewLibraryWindow_SelectCompounds}"
		   HorizontalAlignment="Left">
</TextBlock>
 
Share this answer
 
v3
Comments
Gita Padhihari 14-Oct-21 9:48am    
yes I want to have the same value for Text and Tooltip. I am reading the Text value from resource file. What should I write in my case ? Please suggest.
Gita Padhihari 14-Oct-21 10:53am    
Thank you very much . It is working fine .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900