Skip to content

KeysConverter should use CurrentUICulture when converting to name in default context. #10687

@Tanya-Solyanik

Description

@Tanya-Solyanik

KeysConverter in NET8 started converting keys to strings based on the CurrentCulture -

private IList<string> GetDisplayOrder(CultureInfo? culture)
{
// Use CurrentCulture as default to match other TypeConverters.
culture ??= CultureInfo.CurrentCulture;
if (!CultureToDisplayOrder.ContainsKey(culture))
{
AddLocalizedKeyNames(culture);
}
return CultureToDisplayOrder[culture];
}
private IDictionary<string, Keys> GetKeyNames(CultureInfo? culture)
{
// Use CurrentCulture as default to match other TypeConverters.
culture ??= CultureInfo.CurrentCulture;
if (!CultureToKeyName.ContainsKey(culture))
{
AddLocalizedKeyNames(culture);
}
return CultureToKeyName[culture];
}

However, in .NET Framework, we were looking up names based on the CurrentUICulture - https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/KeysConverter.cs,64 from the resources like this:

AddKey(SR.GetString(SR.toStringPageDown), Keys.Next);

this code goes to ResourceManager.GetString Method (System.Resources) | Microsoft Learn
and returns

The value of the resource localized for the caller's current UI culture, or null if name cannot be found in a resource set.

Originally posted by @cadilhac in #10610 (comment)

Metadata

Metadata

Assignees

Labels

💥 regression-releaseRegression from a public releaseservicing-consider.NET Shiproom label indicating a PR seeks to enter into a branch under Tell-Mode criteria

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions