Weird rendering behavior in WPF for ToolTips with brackets or parentheses

拈花ヽ惹草 提交于 2019-12-24 09:46:13

问题


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>


来源:https://stackoverflow.com/questions/4389649/weird-rendering-behavior-in-wpf-for-tooltips-with-brackets-or-parentheses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!