#374 – Using a Tooltip to Display the Full Contents of a TextBox
August 29, 2011 4 Comments
It might often be the case that a TextBox control is not wide enough to display all of its text (the current value of its Text property).
The user could click in the TextBox control and move the cursor in order to see all of the text, but it would be handy to display the full contents in a tooltip.
You can set up a tooltip to display the full text of the Text property by setting the Tooltip property of the TextBox and using data binding to bind its value to the Text property.
<TextBox Text="Now is the winter of our discontent Made glorious summer by this sun of York; And all the clouds that lour'd upon our house In the deep bosom of the ocean buried." ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Width="100" Margin="10"/>
How could I arrange only to display the tooltip is there if not all the text is displayed in the text box?
This doesn’t seem to work if the TextBox Text itself is bound. Here’s my code:
Pass the same textbox binding element content to Tooltip
Pass the same textbox binding element to tooltip