microsoft / microsoft/microsoft-ui-xaml
How to binding general string indexers?
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
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:
``
But this cannot be done in WinUI3:
``
1. No x:static
2. Binding needs to contain a public constructor
3. Can not work If I switch to x:bind:
4. Is this question related to mine?[(#3064)]
So, In winui3, How to do?
Contributor guide
Research direction
Start by reproducing the posted WinUI 3 binding and x:Bind examples with the LanguageManager sample, then compare their behavior with the related issue #3064. No repository files or tests are named in the report; done would be a documented supported approach for binding the string indexer, or a clear explanation of the limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100