I have a ToolTip with a value set as:
Value="{Binding Path=DataItem.EquitySold, StringFormat=Reserved (Equity Share: \{0\}%)}"
The toolip is displaying as:
72
But I expect it to be:
Reserved (Equity Share: 72%)
What is wrong with my binding?
A toolTip is a content control, which means it doesn't really have a display model. This is demonstrated in the earlier answer by @deccyclone that sets the content to a TextBlock. Since the TextBox is designed to display text, the StringFormat binding property works as advertised. Button is another example of this. (Both derive from ContentControl)
If you set the Content of a ToolTip to a string, the string is displayed because the ToolTip has a built in converter if the dataType is string. If you want to take advantage of that built in string converter, you need to set the format using the ContentStringFormat property.
<ToolTip Content="{Binding Path=Value}" ContentStringFormat="{}{0:F2} M" />
BTW, the tip off for when to use StringFormat or ContentStringFormat is by which property the control supplies for setting the displayed text. Text property -> use StringFormat Content property -> use ContentStringFormat
Have you tried:
<ToolTip> <TextBlock Text="{Binding Path=DataItem.EquitySold, StringFormat=Reserved (Equity Share: \{0\}%)}" /> </ToolTip>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With