HandyControl icon indicating copy to clipboard operation
HandyControl copied to clipboard

Cannot change language (from chinese to English) with HandyControl window used within Excel VSTO Application

Open kababu2021 opened this issue 2 years ago • 4 comments

Describe the bug

ExcelAddInHCSimple.zip

Issue Description:

When HandyControl and HandyControl.Lang.en package for developing Windows on an Excel VSTO Addin development, the language is always defaulting to Chinese, although it is explicitly set to use English.

Sub Issue 1: We cannot just create a new WPF window and set ConfigHelper.Instance.SetLang("en") since it will complain about not having an Application. To work around it, I create an Application window (HcTestApp) and call the WPF window (HcTest) from within it. (a pain, but a workaround, unless someone has a better way to handle this limitation in handycontrol)

Sub Issue 2: Even though this pseudo application sets the Resource dictionary, the sub-window needs to include it again under Window.Resources. This works for now.

What is tried so far:

  1. Have tried setting it in OnStartup() for HcTestApp.xaml as mentioned in this issue comment https://github.com/HandyOrg/HandyControl/issues/527#issuecomment-735360012
  2. Created a sample project to show the issue. The project was developed in VS 2022 with .Net framework 4.8.
  3. Have tried to set the "Lang" property directly. It assigns, but does not work.
  4. Have tried to ask the question in gitter a few times, but could not get a reply.
  5. Did not try HandyControls, since it is the master version as I understand.

Kindly let me know how we can solve this issue. Sub Issue 1 is a problem too, and I don't know if there is a workaround for that.

Steps to reproduce the bug

  1. Unzip the Project
  2. Build the solution and launch.
  3. Excel opens and you can see the add-in on the tab "ExcelAddinHCSimple"
  4. Click on the Button "Simple HC Control"
  5. The user list is a CheckCombobox, which has Select All in Chinese even though we set ConfigHelper.Instance.SetLang("en")

Please refer Screenshot below.

Expected behavior

"Select All" under the CheckComboBox should be shown in "English", but is shown in "Chinese"

Screenshots

image

image

NuGet package version

HandyControl 3.3.0

IDE

Visual Studio 2022

Framework type

.Net Framework 4.8

Windows version

May 2021 Update (19043)

Additional context

No response

kababu2021 avatar May 16 '22 03:05 kababu2021

Update: If I use HandyControls, where the default language is English, it does work. So the issue seems to be with the stable version where the default language is English.

https://github.com/HandyOrg/HandyControl/issues/1132 https://github.com/HandyOrg/HandyControl/discussions/1130

kababu2021 avatar May 16 '22 03:05 kababu2021

Hi 🖐,

I will not download your .zip, however if you can create a github repo I will be able to look at it.

In my project I used to get some langage problem. I define my langage in my MainWindow constructor, the following way :

    /// <summary>
    ///     Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {

        public MainWindow()
        {
            // Define global culture information for reliable double conversions
            CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
            // Set default handy control language to english
            ConfigHelper.Instance.SetLang("en");

            // other things can be initialized here
        } 
    }

Then the 'All' in my CheckComboBox is in English.

Hope it can help you 😊

Yopler avatar May 16 '22 10:05 Yopler

@Yopler Thank you for the quick response.

I have moved the project to https://github.com/kababu2021/ExcelAddinTest from where you could clone.

I tried the method you mentioned and has the same issue still.

kababu2021 avatar May 17 '22 19:05 kababu2021

HandyControl 3.0.0
HandyControl 3.1.0
HandyControl 3.2.0
//Only English and Chinese are valid, the rest are invalid ConfigHelper.Instance.SetLang("en");

image

QiaoHongDian avatar Dec 16 '22 14:12 QiaoHongDian