I'm struggling with a strange issue regarding ToolTip
s in WPF:
First, the code:
<TextBlock Text="{Binding SelectedItem.Approver.Timestamp, StringFormat='{}{0:g}'}"
ToolTip="{Binding SelectedItem.Approver.Timestamp, StringFormat='{}{0:f}'}" />
As you can see, the "g format specifier" (e. g. 2016-12-24 23:42
) is used for the timestamp's display and "f format specifier" (e. g. Saturday, 24. December 2016 23:42
) for its ToolTip
.
However, what I get is: 2016-12-24 23:42
. In other words: the ToolTip
shows exactly the same format as does the TextBlock
.
It gets even weirder when switching the TextBlock
to the "f format specifier", too: the ToolTip
just stays in the format specified by the "g format specifier".
So, I've got two questions:
a) Why is that?
and
b) How to enforce my desired format?
I got it working.
<TextBlock Text="{Binding SelectedItem.Approver.Timestamp, StringFormat={}{0:g}}">
<TextBlock.ToolTip>
<ToolTip Content="{Binding SelectedItem.Approver.Timestamp}" ContentStringFormat="{}{0:f}" />
</TextBlock.ToolTip>
</TextBlock>
As Tooltip can contain anything, we should use its ContentStringFormat.