uno: [Android] `x:Bind` mode `OneTime` doesn't work because `Page` is loaded early when using `NativeFramePresenter`

Current behavior

x:Bind doesn’t properly work on Android.

06-16 13:21:39.635 E/Windows.UI.Xaml.Data.BindingExpression(13378): Failed to apply binding to property [DependencyPropertyDetails(Command)] on [Windows.UI.Xaml.Controls.Primitives.ButtonBase] (Specified cast is not valid.) System.InvalidCastException: Specified cast is not valid.
06-16 13:21:39.635 E/Windows.UI.Xaml.Data.BindingExpression(13378):   at ApplicationTemplate.Views.Content.HomePage.get_VM () [0x00000] in B:\Repos\xbindSample\src\app\ApplicationTemplate.UWP\Views\Content\Welcome\HomePage.xaml.cs:13 
06-16 13:21:39.635 E/Windows.UI.Xaml.Data.BindingExpression(13378):   at ApplicationTemplate.Views.Content.HomePage+<>c.<InitializeComponent>b__4_8 (System.Object ___ctx) [0x00000] in B:\Repos\xbindSample\src\app\ApplicationTemplate.Droid\obj\Debug\100\g\XamlCodeGenerator\HomePage_f3d3c6677e835d082815ec6734517a07.g.cs:119 
06-16 13:21:39.635 E/Windows.UI.Xaml.Data.BindingExpression(13378):   at Windows.UI.Xaml.Data.BindingExpression.Uno.UI.DataBinding.IValueChangedListener.OnValueChanged (System.Object o) [0x00045] in C:\a\1\s\src\Uno.UI\DataBinding\BindingExpression.cs:525 
06-16 13:21:39.635 E/Windows.UI.Xaml.Data.BindingExpression(13378): 

Expected behavior

x:Bind is applied properly on all platforms.

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

Xamarin

  • Launch the following sample. xbindSample.zip
  • Notice that the button in HomePage.xaml works on UWP and iOS, but not on Android.

.Net 7 Mobile

  • Launch the following sample. XBindSampleNet7.zip
  • Notice that the button in HomePage.xaml works on WinUI and iOS, but not on Android.

Environment

Nuget Package:

  • Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
  • Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
  • Uno.SourceGenerationTasks
  • Uno.UI.RemoteControl / Uno.WinUI.RemoteControl
  • Other:

Nuget Package Version(s):

  • 3.6.6
  • 4.8.24

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Skia
    • WPF
    • GTK (Linux)
    • Tizen
  • Windows
  • Build tasks
  • Solution Templates

Anything else we need to know?

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 31 (31 by maintainers)

Most upvoted comments

Yes, that’s using the template you provided which does not specify a mode. OneTime is the default for x:Bind.

@jeromelaban I updated the description to include a repro that targets .Net 7 mobile. (It’s very similar to the Xamarin sample.)

@jeromelaban if datacontext changes consistently on every page load on Android, wouldn’t this cause all bindings to be evaluated twice? And maybe even have the pages relayout themselves following those binding updates?

Fixing this issue could have major performance improvements. cc @jeanplevesque