Repository navigation
Open
Open
Copy link
Labels
area/xBind 🪢Categorizes an issue or PR as relevant to x:Binddifficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandinghas-repro-branchkind/bugSomething isn't workingplatform/android 🤖Categorizes an issue or PR as relevant to the Android platformplatform/ios 🍎Categorizes an issue or PR as relevant to the iOS platformplatform/wasm 🌐Categorizes an issue or PR as relevant to the WebAssembly platformproject/binding 🪢Categorizes an issue or PR as relevant to the binding engineproject/navigation-lifecycle 🧬Categorizes an issue or PR as relevant to the navigation and lifecycle (NavigationView, AppBar, ...)triage/potentially-fixedCategorizes an issue as potentially fixed by some unlinked PR, fix needs to be verified
Description
Current behavior
When await is used before first navigation in App.xaml.cs, x:Bind suddenly behaves "weirdly" - it binds data which are available during page constructor, but does not consider any updates during OnNavigatedTo (which is when MVVM frameworks like MvvmCross set the DataContext).
Expected behavior
x:Bind behavior should not change if user awaits in OnLaunched.
How to reproduce it (as minimally and precisely as possible)
- Create a new Uno Platform app
- Set MainPage.xaml as follows:
<Page
x:Class="BindBreak.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BindBreak"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock Text="{x:Bind Text}" Margin="20" FontSize="30" />
</Grid>
</Page>
- Set code-behind as follows:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace BindBreak
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.DataContextChanged += MainPage_DataContextChanged;
}
private void MainPage_DataContextChanged(DependencyObject sender, DataContextChangedEventArgs args)
{
Text = "In data context changed";
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
DataContext = new object();
}
public string Text { get; set; } = "Should not display";
}
}
- Run the app on UWP, Android. Notice in both cases app says "In data context changed"
- In App.xaml.cs change
OnLaunchedto be async:
protected override async void OnLaunched(LaunchActivatedEventArgs e)
- Add delay before navigating in
OnLaunched:
await Task.Delay(1000);
rootFrame.Navigate(typeof(MainPage), e.Arguments);
- Launch app on UWP. Observe there is no change in behavior.
- Launch app on Android. Observe it now shows "Should not display".
Workaround
Add the following statement at the end of the OnNavigatedTo method:
Bindings.Update();
Environment
Nuget Package: latest stable + latest dev
Package Version(s):
Affected platform(s):
- iOS
- Android
- WebAssembly
- WebAssembly renderers for Xamarin.Forms
- macOS
- Windows
- Build tasks
- Solution Templates
Visual Studio:
- 2017 (version: )
- 2019 (version: )
- for Mac (version: )
Relevant plugins:
- Resharper (version: )
Anything else we need to know?
Metadata
Metadata
Assignees
Labels
area/xBind 🪢Categorizes an issue or PR as relevant to x:Binddifficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandinghas-repro-branchkind/bugSomething isn't workingplatform/android 🤖Categorizes an issue or PR as relevant to the Android platformplatform/ios 🍎Categorizes an issue or PR as relevant to the iOS platformplatform/wasm 🌐Categorizes an issue or PR as relevant to the WebAssembly platformproject/binding 🪢Categorizes an issue or PR as relevant to the binding engineproject/navigation-lifecycle 🧬Categorizes an issue or PR as relevant to the navigation and lifecycle (NavigationView, AppBar, ...)triage/potentially-fixedCategorizes an issue as potentially fixed by some unlinked PR, fix needs to be verified
Activity
MartinZikmund commentedon Mar 23, 2020
After a bit further digging, the async is not the main issue - when we add another page with the same logic and add a button to
MainPageto navigate to it, the second page shows "Should not display" even ifOnLaunchedis not async. So it seems for any page that not loaded immediately after start of the application x:Bind behaves "incorrectly"MartinZikmund commentedon Mar 23, 2020
Added higher priority, as this is important for MvvmCross apps to work seamlessly when Uno support is added.
jeromelaban commentedon Mar 24, 2020
It seems one of the problems is the ordering of page Loaded and navigation events and overrides, which may be related to #2008.
MartinZikmund commentedon Mar 24, 2020
@jeromelaban Oh, I must ping him.
I have also noticed the reason is probably the event ordering - for subsequent navigations,
Loadedevent runs beforeOnNavigatedTo, which means view model/DataContext is not set yet and hence things likeViewAppearing/ViewAppearedin MvvmCross stop working.MartinZikmund commentedon Mar 24, 2020
Leaving here for reference - https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.page.onnavigatedto#remarks -
OnNavigatedToshould always be called beforeLoadedMartinZikmund commentedon Mar 27, 2020
This is caused by #2895.
10 remaining items
[-]Async OnLaunched magically breaks x:Bind[/-][+]x:Bind is evaluated too early causing changes in Page.OnNavigatedTo to be ignored[/+]hawkerm commentedon Mar 14, 2022
Not sure if related or slightly different, but I'm using the common behavior/load pattern to do async initialization of my ViewModel:
So while
Bindings.Update()appears to work the first load, this trigger for theLoadedis being missed on subsequent page navigations in WPF/WASM, where it works fine in UWP.I may have to see if I can just move this behavior to the OnPageNavigated override instead though, but is another quirk of the loading order being out of order. Will have to test that out later.
[-]x:Bind is evaluated too early causing changes in Page.OnNavigatedTo to be ignored[/-][+]`x:Bind` is evaluated too early causing changes in `Page.OnNavigatedTo` to be ignored[/+]MartinZikmund commentedon Jul 17, 2025
This is likely still relevant for Skia targets
test: Reproduce x:Bind evaluated too early before OnNavigatedTo
MartinZikmund commentedon Apr 7, 2026
Repro generator
Runtime test(s) added in branch
dev/mazi/repro/2872:src/Uno.UI.RuntimeTests/Tests/BindingTests/Given_XBind_NavigatedTo.cs→When_XBind_Updated_After_DataContext_Set_In_OnNavigatedToawaitinOnLaunched), navigating to a page that setsDataContextinOnNavigatedTo(which callsBindings.Update()) correctly updates the{x:Bind}bound property. This is consistent with thetriage/potentially-fixedlabel. The branch provides a regression guard for the managed path. The original bug was reported on iOS/Android/WASM.MartinZikmund commentedon Apr 8, 2026
Repro generator
A PR has been created to add the passing regression test(s) from branch
dev/mazi/repro/2872:The test(s) pass on current master (Skia target), suggesting the reported issue may be fixed. The issue was reported on iOS, Android, WebAssembly — verification on native targets is still recommended.
test: Reproduce x:Bind evaluated too early before OnNavigatedTo
Merge pull request #22991 from unoplatform/dev/mazi/repro/2872