WPF 中带有方括号或圆括号的工具提示的奇怪呈现行为

发布于 2024-10-06 15:31:55 字数 583 浏览 5 评论 0原文

我有一个按钮,其工具提示定义如下:

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

当我在运行时将鼠标悬停在按钮上时,工具提示显示为

(.删除选定的名称 (Ctrl + F12

我也尝试过定义工具提示,因为

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

我也尝试过使用括号而不是圆括号。

在所有情况下,最终结束后的文本)或 ] 被切断并附加到字符串的前面,以开头 ( 或 [ 为前缀。我已经在 google 上搜索了工具提示所需的任何特殊转义提示,但结果却很干燥。我是在某个地方错过了明显的内容,还是我最终会失去控制?:-|

这是使用.Net框架4.0版本。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海风掠过北极光 2024-10-13 15:31:55

这有点晚了,但我刚刚遇到这个问题,找不到解决方案。我的不涉及句号,添加空格也没有帮助。

我有一个按钮,其内容绑定到我的视图模型上的一个字符串,类似于“count (0)”,并呈现为“( count (0”)。经过一些修改和使用按钮的模板后,我发现我的按钮包含在 StackPanel 中,其 FlowDirection 设置为 RightToLeft 似乎 Button 控件从父级继承了此值,因此一旦我将 Button 的 FlowDirection 设置回 LeftToRight,问题就解决了

。关于它改变渲染时文本顺序的根本原因,但至少这个解决方案似乎解决了问题。

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.

别靠近我心 2024-10-13 15:31:55

我刚刚遇到了同样的问题,我做了一些解决方法,只是在点后面加一个空格,它就像一个魅力。

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.

哥,最终变帅啦 2024-10-13 15:31:55

迟到了,但我有解决办法。

当 TextBlock/Label 以 RoghtToLeft 流用 StackPanel 包装时,会出现问题。
例如:

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

解决方法是使用附加属性:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文