Weird rendering behavior in WPF for ToolTips with

2019-07-30 09:23发布

问题:

I have a button with a tool tip defined as follows:

<Button Width="25" ToolTip="Delete selected name (Ctrl + F12).">-</Button>

When I hover over the button at run time the tooltip displays as

(.Delete selected name (Ctrl + F12

I have also tried defining the tooltip as

<Button Width="25">
  <Button.ToolTip>Delete selected name (Ctrl + F12).</Button.ToolTip>
  -
</Button>

I have also tried using brackets instead of parentheses.

In all cases text after the final closing ) or ] is being cut off and perpended to the front of the string, prefixed by an opening ( or [. I have googled for any hint of special escaping needed for tool tips and come up dry. I am I missing the obvious somewhere or am I going finally loosing my grip? :-|

This is using the 4.0 version of the .Net framework.

回答1:

I've just encountered the same problem, I've done a bit of a workaround which simply was to put a space after a dot and it works like a charm.



回答2:

This is a little late, but I just had this problem and could not find a solution. Mine did not involve a period and adding a space did not help.

I had a Button with its content bound to a string on my view model that was something like "count (0)" and was rendering as "( count (0". After some tinkering around and playing with the button's template, I discovered that my button was contained in a StackPanel with its FlowDirection set RightToLeft. It would seem that the Button control inherits this value from the parent, so as soon as I set the Button's FlowDirection back to LeftToRight, the problem was solved.

I don't know the underlying reason as to why it changes the text's order on render, but at least this solution seems to fix the problem.



回答3:

Late, but I have got workaround.

Problem appears when TextBlock/Label is wrapped with StackPanel with flow RoghtToLeft. For example:

<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
    <Label Content="New document (Z) " Width="200" />
</StackPanel>

Workaround is to use attached property:

<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
    <Label Content="New document (Z) " Width="200" StackPanel.FlowDirection="LeftToRight" />
</StackPanel>