问题
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 setFormat
asEnglish (United States)
- go
Additional settings/Numbers
and changeDecimal 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