unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.62k stars 696 forks source link

[iOS][Android] Error binding `PasswordBox.PasswordRevealMode` #9915

Open juliecantin opened 1 year ago

juliecantin commented 1 year ago

Current behavior

On Android and iOS, trying to bind PasswordBox.PasswordRevealMode results in a runtime error, even though the same binding succeeds on UWP.

iOS: System.InvalidOperationException Message=Failed to load MyUnoApp2.MainPage: System.ArgumentOutOfRangeException: No strategy registration for conversion 'PasswordRevealMode' to 'Boolean' Parameter name: extensionPoint at Uno.Conversion.DefaultConversionExtensions.To (System.Object value, System.Type toType, System.Globalization.CultureInfo culture) [0x0002e] in C:\a\1\s\src\Uno.Foundation\Uno.Core.Extensions\Uno.Core.Extensions.Compatibility\Conversion\DefaultConversionExtensions.cs:85 at Uno.UI.DataBinding.BindingPropertyHelper.ConvertWithConvertionExtension (System.Object value, System.Type t) [0x00016] in C:\a\1\s\src\Uno.UI\DataBinding\BindingPropertyHelper.cs:1106 at Uno.UI.DataBinding.BindingPropertyHelper.Convert (System.Func`1[TResult] propertyType, System.Object value) [0x0003a] in C:\a\1\s\src\Uno.UI\DataBinding\BindingPropertyHelper.cs:1081 at Uno.UI.DataBinding.BindingPropertyHelper+<>c__DisplayClass40_9.b__13 (System.Object instance, System.Object value) [0x00000] in C:\a\1\s\src\Uno.UI\DataBinding\BindingPropertyHelper.cs:858 at Windows.UI.Xaml.Data.BindingExpression.SetTargetValue (System.Object value) [0x0000f] in C:\a\1\s\src\Uno.UI\DataBinding\BindingExpression.cs:426 at Windows.UI.Xaml.Data.BindingExpression.ApplyFallbackValue (System.Boolean useTypeDefaultValue) [0x00030] in C:\a\1\s\src\Uno.UI\DataBinding\BindingExpression.cs:344 at Windows.UI.Xaml.Data.BindingExpression..ctor (Uno.UI.DataBinding.ManagedWeakReference viewReference, Windows.UI.Xaml.DependencyPropertyDetails targetPropertyDetails, Windows.UI.Xaml.Data.Binding binding) [0x00147] in C:\a\1\s\src\Uno.UI\DataBinding\BindingExpression.cs:137 at Windows.UI.Xaml.DependencyPropertyDetailsCollection.SetBinding (Windows.UI.Xaml.DependencyProperty dependencyProperty, Windows.UI.Xaml.Data.Binding binding, Uno.UI.DataBinding.ManagedWeakReference target) [0x00014] in C:\a\1\s\src\Uno.UI\UI\Xaml\DependencyPropertyDetailsCollection.Bindings.cs:132 at Windows.UI.Xaml.DependencyObjectStore.SetBinding (Windows.UI.Xaml.DependencyProperty dependencyProperty, Windows.UI.Xaml.Data.BindingBase binding) [0x0002e] in C:\a\1\s\src\Uno.UI\UI\Xaml\DependencyObjectStore.Binder.cs:390 at Uno.UI.Controls.BindableUIView.SetBinding (Windows.UI.Xaml.DependencyProperty dependencyProperty, Windows.UI.Xaml.Data.BindingBase binding) [0x00000] in C:\a\1\s\src\Uno.UI\obj\Release\xamarinios10\g\DependencyObjectGenerator\Uno_UI_Controls_BindableUIView_283f42f32036f7bd27e98620585dab23.g.cs:336

Android: System.NullReferenceException Message=Object reference not set to an instance of an object.

Expected behavior

Binding PasswordBox.PasswordRevealMode succeeds

How to reproduce it (as minimally and precisely as possible)

MyUnoApp2.zip

Workaround

Set PasswordRevealMode another way, such as through code-behind or a behavior.

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

4.5.9

Affected platforms

iOS, Android

IDE

Visual Studio 2022

IDE version

17.2.2

Relevant plugins

No response

Anything else we need to know?

No response

jeromelaban commented 1 year ago

Thanks for the report. This is indeed a curious behavior from WinUI, as this enum has three values. What's your intent here when binding to a boolean?

juliecantin commented 1 year ago

It's mostly to avoid referencing a view-specific type in the ViewModel and also because we only want to switch between two of these modes (Visible and Hidden).

However, I'll note that the sample uses a converter so that the value passed to the password-box is of type PasswordRevealMode, and that the same error occurs if we bind directly to a property of type PasswordRevealMode in the ViewModel.

jeromelaban commented 1 year ago

Thanks. In all cases, I wonder if WinUI treats true as 1 and false as 0 when binding to enums. We'll have to investigate.

Note that you can also use x:Bind functions to make it simpler (and more explicit).