maui
maui copied to clipboard
[Windows] [RC2] Conditional ToolbarItem Text Display Using OnIdiom Not Working in Release Mode
Description
When I use Text="{ext:Translate ProfileToolBarText}"
without OnIdiom
, it works correctly in both Release and Debug modes. However, I intend to display the text on Desktop only, but this setup only works in Debug mode. In Release mode, it incorrectly displays Microsoft.Maui.Controls.Binding
Behavior in Release Mode (incorrect)
Behavior in Debug Mode (expected):
No exceptions are evident in the output that could indicate the root cause. The issue seems to arise when using OnIdiom.
Steps to Reproduce
- Clone the Repository.
- Run the application in Release Mode.
- You will notice the text is displaying
Microsoft.Maui.Controls.Binding
.
Link to public reproduction project repository
https://github.com/malsabi/ToolBarItemIssue
Version with bug
8.0.0-rc.2.9511
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows10.0.19041.0
Did you find any workaround?
No I didn't find any workaround.
Relevant log output
No response
@StephaneDelcroix Thoughts?
one path is using SetValue, the other is using SetBinding... I would not have considered this as a bug and only a possible enhancement, but the mismatch between debug and release require a solution
one path is using SetValue, the other is using SetBinding... I would not have considered this as a bug and only a possible enhancement, but the mismatch between debug and release require a solution
Is there any workaround that we can use at the moment ?
@StephaneDelcroix If there's any workaround for this issue please let me know, we are deploying our app on December.
@malsabi i have it working like this in case you don't need anything from the binding public object ProvideValue(IServiceProvider serviceProvider) { return Translator.Instance[Key]; }
Just return the string value and it will work in both debug/release
@cgomezm Hello thanks for replying. I tried the approach but it didn't work on release mode it kept on crashing, here is how I tried it: Maybe you could create a PR to the same repo I provided earlier.
namespace ToolBarItemIssue.Common.Extensions
{
[ContentProperty(nameof(Name))]
public class TranslateExtension : IMarkupExtension<BindingBase>
{
public string? Name { get; set; }
public BindingBase ProvideValue(IServiceProvider serviceProvider)
{
throw new NotImplementedException();
}
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
{
if (string.IsNullOrEmpty(Name))
return "N/A";
return LocalizationResourceManager.Instance[Name];
}
}
}
@malsabi I moved away from returning the binding and just return the string value.
[ContentProperty(nameof(Key))]
internal class TranslateExtension : IMarkupExtension
{
public string Key { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
return Translator.Instance[Key];
}
}
@cgomezm I can confirm your code works on Release / Debug mode however when I try to change the language in runtime it does not work. I tried using the following snippet:
if (AppResources.Culture.TwoLetterISOLanguageName.Equals("en"))
{
LocalizationResourceManager.Instance.SetCulture(new CultureInfo("ar"));
}
else
{
LocalizationResourceManager.Instance.SetCulture(new CultureInfo("en"));
}
@malsabi yeah, that could be a downside as is the value being returned instead of the binding. Maybe dotnet team has made some progress on their investigation of this.
@jsuarezruiz any thoughts or progress about this issue ?
Can repro this issue at Windows platform on the latest 17.10.0 Preview 3(8.0.7&8.0.20).
We can not fix this, in either way: it's not possible (using a reasonable effort) to make it succeed (in all cases) when XamlC is on, and it's not possible to have it fail when XamlC is off
one way would be to deprecate OnIdiom in favour of OnIdiom<TReturnType> (oh, well, it used to be that way)
found a solution, finally
found a solution, finally
Can you tell us what was the solution ? Is there any changes we need to know about ?