Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tooltip culture is wrong

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;
    }
}
like image 798
Sinatr Avatar asked May 12 '16 09:05

Sinatr


1 Answers

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>
like image 159
Smirti Avatar answered Sep 28 '22 09:09

Smirti