I have a TranslateExtension that I use in Avalonia, and WPF to translate some stuff, the code is pretty simple.
public class TranslateExtension : MarkupExtension
{
public TranslateExtension(string key)
{
this.Key = key;
}
public string Key { get; set; }
public string FallBack { get; set; }
public string Context { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
....
var binding = new BindingExtension($"[{keyToUse}]")
{
Mode = BindingMode.OneWay,
Source = Translator.Instance,
FallbackValue = fallback,
};
return binding.ProvideValue(serviceProvider);
}
}
Bascialy, when the is no translation for a specific key (returns null), a fallback value is used instead.
This extension works fine with WPF, and Avalonia 0.8.3.
The problem occurs with the latest version 0.9 preview 3, where it seems that it's ignoring the FallbackValue
@braca I've not had chance to look into this properly, but does it work if you return a Binding rather than a BindingExtension from ProvideValue?
My guess is that Portable.Xaml supported markup extensions returning markup extensions recursively, whereas our XAML compiler doesnt. In fact I'm not even sure that recursive binding extensions should work, it might have just been a "hidden" feature of Portable.Xaml.
@grokys I think this is not a bug after all, my bad. In WPF the behaviour is the same, I thought it wasn't but my WPF code had a small difference, and that makes all the difference.
In WPF I'm using TargetNullValue alongside with FallbackValue.
Removing the TargetNullValue, WPF behaves the same way Avalonia 0.9.
Our translator returns null when there is no translation available for the key. null is a valid 'value' for string, so the correct behaviour seems to be, to use null, instead of the fallbackvalue.
So, I believe that the bug was on 0.8.x where it was behaving differently from WPF :)
Hi,
I have a TranslateExtension that I use in Avalonia, and WPF to translate some stuff, the code is pretty simple.
Bascialy, when the is no translation for a specific key (returns null), a fallback value is used instead.
This extension works fine with WPF, and Avalonia 0.8.3.
The problem occurs with the latest version 0.9 preview 3, where it seems that it's ignoring the
FallbackValue
Repro project: https://github.com/braca/avalonia-binding-fallback-bug
You can load my repro project, with 0.8.3 it will work perfectly, if you update to the latest 0.9 preview 3, the fallback value won't be used.
Note: When you update to the latest preview, comment this
using Portable.Xaml.Markup;
inTranslateExtensions.cs
The text was updated successfully, but these errors were encountered: