2

I've built a very basic WPF, but the context menus which appear when right-clicking on scrollbars or text selections remain in English, even when the local language/regional settings was changed to a different language. Code is attached at the bottom of this post.

At first, I thought maybe I didn't change all the language related settings on a system level, but when I try that in notepad, it works fine (meaning, the right-click menu isn't in English). So I thought maybe it's some kind of a .net/WPF-specific issue, so I checked with Paint.net and it was fine there as well (though it might be non-WPF C# and C++ mixed?). Also tried to install the latest .net Framework Language Pack, which wouldn't install because it already exists on my PC.

You can see the differences in context menus between my app and Notepad in the following screenshots:

notepad my app

The code for the example app which reproduces this problem is pretty basic. This is the xaml file:

<Window x:Class="WpfTestScrollLanguage.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfTestScrollLanguage"
    mc:Ignorable="d"
    Loaded="Window_Loaded"
    Language="uk-ua"
    xml:lang="uk-UA"
    Title="MainWindow" Height="100" Width="525">
<Grid Height="300" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" Language="uk-ua" xml:lang="uk-UA">
    <ListView Language="uk-ua" xml:lang="uk-UA">
        <Button Content="A" Height="20" Width="20"/>
        <Button Content="B" Height="20" Width="20"/>
        <Button Content="C" Height="20" Width="20"/>
        <Button Content="D" Height="20" Width="20"/>
        <TextBlock Height="300" Name="Text"/>
        <TextBox Height="50" Width="300" Text="test123" Language="uk-ua" xml:lang="uk-UA"/>
    </ListView>
</Grid>

and this is the .xaml.cs file that goes along with it (only the code that isn't auto-generated):

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var test = System.Globalization.CultureInfo.CurrentCulture;
    var test2 = System.Globalization.CultureInfo.CurrentUICulture;
    var test3 = this.Language;
    var test4 = System.Windows.Markup.XmlLanguage.GetLanguage(System.Threading.Thread.CurrentThread.CurrentUICulture.Name);
    Text.Text = "a\nb\nc\nd\ne\nf";
}

all of the test variables in runtime have shown "uk-UA" (as I've changed the OS language and region to Ukraine) even without setting those values manually within the xaml file itself. I just added them explicitly to the UI elements defined in the xaml file, to make sure I cover all possible cases.

edit: the app.config file is pretty simple, and doesn't seem related in this scenario:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
</configuration>

Any idea about what I might be missing here? (Running on Windows 10 RS1, but I've observed the same problem also in RS2 and RS3-beta)

edit2: I've tried to find some existing apps that are based on WPF solely, and found WittyTwitter - there it seems that the text's context menu remains in English as well, but the whole app is English only so I can't really tell if maybe it's designed to be like that, or maybe it's really a WPF-based bug?

edit3: someone flagged this question as a dup of this one. Even though it might be more or less the same case, the answer there doesn't solve it (as I've described here), plus my question has more details to reproduce the problem.

Yoav Feuerstein
  • 1,925
  • 2
  • 22
  • 53
  • @AGrammerPro added the app.config file, though it's really basic and simple in this case. I assume that since I didn't mention any explicit value, it should use the default that's in the OS settings. – Yoav Feuerstein Oct 17 '17 at 13:13
  • What language is your .NET Framework on the machine? – Rand Random Oct 17 '17 at 13:17
  • 1
    correct, it should be app.config. My apologies! I have deleted my comment – AGrammerPro Oct 17 '17 at 13:18
  • @RandRandom English I guess, but the language pack should already be installed (as I've mentioned in the original question). – Yoav Feuerstein Oct 17 '17 at 13:18
  • @YoavFeuerstein reading is so hard, I only looked at the picture and that was the first thing that poped up :) – Rand Random Oct 17 '17 at 13:19
  • 1
    Possible duplicate of [Why WPF ScrollViewer Language is tr but ContextMenu command texts are in English?](https://stackoverflow.com/questions/2147953/why-wpf-scrollviewer-language-is-tr-but-contextmenu-command-texts-are-in-english) – Sinatr Oct 17 '17 at 13:24
  • @Sinatr thanks, please see "edit3" at the bottom of my post. – Yoav Feuerstein Oct 17 '17 at 13:31
  • Try to move your language assignments from Window.xaml to App.xaml. I don't know if it helps, but at least App is at the root of your application. – grek40 Oct 17 '17 at 13:32
  • Did you install localized version of net framework (those menu strings are from there, you can change language when downloading one)? Did you [change wpf culture](https://stackoverflow.com/a/24135792/1997232) (by default it's en-US)? – Sinatr Oct 17 '17 at 13:35
  • @grek40 good idea, but seems irrelevant - when I try to do so, as part of the "Application" tag in the App.xml file, I get a warning in the editor that says "The member 'Language' is not recognized or is not accessible" (and then the code won't compile) – Yoav Feuerstein Oct 17 '17 at 13:36
  • @Sinatr as mentioned earlier, I have the English version installed from earlier, but I've already applied its language pack (or so it seems, at least). Regarding the post you've mentioned, I did notice (inside Window_Loaded) that `System.Globalization.CultureInfo.DefaultThreadCurrentCulture` is null, so I tried to assign it with a value, but that didn't seem to change anything. – Yoav Feuerstein Oct 17 '17 at 13:45

0 Answers0