HandyControl
HandyControl copied to clipboard
Cannot change language (from chinese to English) with HandyControl window used within Excel VSTO Application
Describe the bug
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:
- Have tried setting it in OnStartup() for HcTestApp.xaml as mentioned in this issue comment https://github.com/HandyOrg/HandyControl/issues/527#issuecomment-735360012
- Created a sample project to show the issue. The project was developed in VS 2022 with .Net framework 4.8.
- Have tried to set the "Lang" property directly. It assigns, but does not work.
- Have tried to ask the question in gitter a few times, but could not get a reply.
- 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
- Unzip the Project
- Build the solution and launch.
- Excel opens and you can see the add-in on the tab "ExcelAddinHCSimple"
- Click on the Button "Simple HC Control"
- 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
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
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
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 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.
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");