Open
Description
I have a general language change singleton class
public class LanguageManager : INotifyPropertyChanged
{
private readonly ResourceManager _resourceManager;
private static readonly Lazy Lazy = new(() => new LanguageManager());
public static LanguageManager Instance => Lazy.Value;
private LanguageManager()
{
_resourceManager = new ResourceManager(typeof(Resource));
}
public string this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return _resourceManager.GetString(name)!;
}
}
public void ChangeLanguage(string languageName)
{
var culture = CultureInfo.GetCultureInfo(languageName);
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Item[]"));
}
public event PropertyChangedEventHandler? PropertyChanged;
}
In WPF you can do this:
<TextBlockText="{Binding [Welcome], Source={x:Static localization:LanguageManager.Instance}}" />
But this cannot be done in WinUI3:
<TextBlock Text="{Binding [Welcome], Source={x:Static localization:LanguageManager.Instance}}" />
- No x:static
- Binding needs to contain a public constructor
- Can not work If I switch to x:bind:
- Is this question related to mine?[([Feature] x:Bind should support general string indexers without interface in C# #3064)]
So, In winui3, How to do?