mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2025-03-21 13:05:45 -05:00

* Avoid Avalonia CompiledBindingPathBuilder.SetRawSource * Improve UI language change performance
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using Avalonia.Data.Core;
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Markup.Xaml.MarkupExtensions;
|
|
using Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings;
|
|
using System;
|
|
|
|
namespace Ryujinx.Ava.Common.Locale
|
|
{
|
|
internal class LocaleExtension : MarkupExtension
|
|
{
|
|
public LocaleExtension(LocaleKeys key)
|
|
{
|
|
Key = key;
|
|
}
|
|
|
|
public LocaleKeys Key { get; }
|
|
|
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
{
|
|
LocaleKeys keyToUse = Key;
|
|
|
|
var builder = new CompiledBindingPathBuilder();
|
|
|
|
builder
|
|
.Property(new ClrPropertyInfo("Item",
|
|
obj => (LocaleManager.Instance[keyToUse]),
|
|
null,
|
|
typeof(string)), (weakRef, iPropInfo) =>
|
|
{
|
|
return PropertyInfoAccessorFactory.CreateInpcPropertyAccessor(weakRef, iPropInfo);
|
|
});
|
|
|
|
var path = builder.Build();
|
|
|
|
var binding = new CompiledBindingExtension(path)
|
|
{
|
|
Source = LocaleManager.Instance
|
|
};
|
|
|
|
return binding.ProvideValue(serviceProvider);
|
|
}
|
|
}
|
|
}
|