Tooltip culture is wrong

杀马特。学长 韩版系。学妹 提交于 2019-12-10 13:28:36

问题


I have in xaml:

<TextBlock Text="{local:Bind Test}" ToolTip="{local:Bind Test}" />

And here is screenshot (using magnifier):

My question is what is going on here? Why tooltip displays value differently (decimal point is . while , is expected)?


Longer story:

I am trying to display numbers in same format as in user Windows number format preferences.

For this I've override the language before displaying window (overriding App.OnStartup):

FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

And using following custom binding (to set converter culture by default)

public class Bind : Binding
{
    public Bind(string path) : base(path)
    {
        ConverterCulture = CultureInfo.CurrentCulture;
    }
}

It works for Text property of TextBox, but it doesn't work for ToolTip.

To actually see what I show on screenshot:

  • go (Windows 7) Control Panel/Region and Language/Formats and set Format as English (United States)
  • go Additional settings/Numbers and change Decimal symbol from . to ,
  • create new wpf application, copy xaml, add language override, add converter and set:

public partial class MainWindow : Window
{
    public double Test { get; set; } = 1.234567;

    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
    }
}

回答1:


I'm also facing the same problem. So you can resolve this by adding TextBlock inside the ToolTip and bind the same Text="{local:Bind Test}" for this ToolTip's TextBlock also.

<TextBlock>
    <TextBlock.ToolTip>
        <TextBlock Text="{local:Bind Test}"/>
    </TextBlock.ToolTip>
</TextBlock>


来源:https://stackoverflow.com/questions/37182987/tooltip-culture-is-wrong

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