Last active
February 9, 2021 18:27
-
-
Save jp2masa/6b427f2bfc925fd7a3b2cea3efddf3f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal sealed class TranslationBinding : IBinding | |
{ | |
private readonly IBinding _binding; | |
public TranslationBinding(IBinding binding) | |
{ | |
_binding = binding; | |
} | |
public InstancedBinding Initiate(IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor = null, bool enableDataValidation = false) | |
{ | |
var instance = _binding.Initiate(target, null); | |
IBinding CreateTranslationBinding(string translationKey) => | |
new Binding($"[{translationKey}]") | |
{ | |
Mode = BindingMode.OneWay, | |
Source = TranslationManager.Instance, | |
}; | |
var observable = from x in instance.Subject | |
from y in IsTranslation((string)x, out var key) | |
? CreateTranslationBinding(key).Initiate(target, null).Subject | |
: Observable.Return(x) | |
select y; | |
return new InstancedBinding(Subject.Create<object>(Observer.Create<object>(x => { }), observable), BindingMode.OneWay, instance.Priority); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment