Repository navigation
Closed as not planned
Labels
difficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandingepickind/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/macos 🍏Categorizes an issue or PR as relevant to the macOS platformplatform/wasm 🌐Categorizes an issue or PR as relevant to the WebAssembly platformproject/navigation-lifecycle 🧬Categorizes an issue or PR as relevant to the navigation and lifecycle (NavigationView, AppBar, ...)
Description
Current behavior
The Loading and Loaded events are called immediately after the control is added in the visual tree.
Expected behavior
The controls start Loading and get Loaded only once the UI thread is freed up.
How to reproduce it (as minimally and precisely as possible)
I have two examples that demonstrate the differences.
Frame navigation
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
Debug.WriteLine("Page constructor");
Loading += MainPage_Loading;
Loaded += MainPage_Loaded;
}
private void MainPage_Loading(FrameworkElement sender, object args)
{
Debug.WriteLine("Page loading");
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
Debug.WriteLine("Page navigating from");
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
Debug.WriteLine("Page navigated to");
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Page loaded");
}
}
// navigating to the page
frame.Navigating += RootFrame_Navigating;
frame.Navigated += RootFrame_Navigated;
frame.NavigationStopped += RootFrame_NavigationStopped;
frame.Navigate(typeof(MainPage));
Debug.WriteLine("After Navigated");
The output is:
Frame navigating
Page constructor
Frame navigated
Page navigated to
After navigated
Page loading
Page loaded
Whereas in case of Uno it is:
Frame navigating
Page constructor
Page loading
Page loaded
Frame navigated
Page navigated to
After navigated
Creating & throwing away many controls
public partial class CustomControl : Control
{
public CustomControl()
{
this.Loading += CustomControl_Loading;
this.Loaded += CustomControl_Loaded;
}
private void CustomControl_Loading(
Windows.UI.Xaml.FrameworkElement sender,
object args)
{
Debug.WriteLine("Loading");
}
private void CustomControl_Loaded(
object sender,
Windows.UI.Xaml.RoutedEventArgs e)
{
Debug.WriteLine("Loaded");
}
private void CustomControl_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
Debug.WriteLine("UnLoaded");
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
}
// in button click handler
private void Button_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 1000; i++)
{
var btn = new CustomControl();
Content = btn;
}
Debug.WriteLine("After for loop");
}
Output on UWP:
After for loop
Loading
Loaded
999x Unloaded
Output on Uno:
Loading
Loaded
Unloaded
Loading
Loaded
Unloaded
... 997x the same
Unloaded
Loading
Loaded
After for loop
Environment
Nuget Package: 2.0
Package Version(s): 2.0
Affected platform(s):
- iOS
- Android
- WebAssembly
- WebAssembly renderers for Xamarin.Forms
- macOS
- Windows
- Build tasks
- Solution Templates
Reacted by Vítězslav Imrýšek, Agnès ZITTE, Jean-Philippe Lévesque, Maxim Marinchenko and d2dyno
Metadata
Metadata
Assignees
Labels
difficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandingepickind/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/macos 🍏Categorizes an issue or PR as relevant to the macOS platformplatform/wasm 🌐Categorizes an issue or PR as relevant to the WebAssembly platformproject/navigation-lifecycle 🧬Categorizes an issue or PR as relevant to the navigation and lifecycle (NavigationView, AppBar, ...)
Activity
[-]Loading & Loaded events are called too early[/-][+]Loading, Loaded & Unloaded events are called too early[/+]MartinZikmund commentedon Mar 27, 2020
I have updated the issue with
Unloadedevent as well, as it is affected too.MartinZikmund commentedon Mar 27, 2020
Out of curiosity I tried to implement this "delayed"
LoadingandLoadedreporting for iOS only in this branch. This implementation is surely not ideal solution, handlesFrameworkElementonly and does not fixUnloaded, but the Samples app runs fine even after this change.Essentially instead of raising
OnLoadingandOnLoadedimmediately, they are enqueued and then batch executed when UI thread is available.nor0x commentedon Apr 21, 2020
not sure if this is related, but with the current version the splash screen is not disappearing once the app is already loaded, i have tested this on
WASMThe following block doesn't get removed or hidden for me.
MartinZikmund commentedon May 2, 2020
@jeromelaban Is it realistic to resolve this without significant breaking changes? It is probably the main blocker for MvvmCross support. If it cannot be solved easily, I will check if MvvmCross.Uno code can be modified to circumvent this somehow.
jeromelaban commentedon May 4, 2020
It is realistic (and required) to fix this without breaking changes, but it would most likely be fixed properly by porting the original Frame code. I would suggest that, for now, modifying the MvvmCross code to adjust for the behavior is the safest course of action.
Note that
FrameworkElement.IsLoadedis available in WinUI and can be used to compensate for this behavior in a backward compatible way, once this is fixed in Uno.MartinZikmund commentedon May 4, 2020
I think the problem is not only in Frame, but in other controls too - the Loaded event is in general called immediately after the control is attached to tree, whereas in UWP it is executed after the UI thread is free - see the CustomControl example code in the issue description.
We were looking into it with @nickrandolph , the problem for MvvmCross can be worked around for now by using INotifyPropertyChanged on the page and notifying after the VM was set to refresh all x:Binds (but it also means all x:Bind must be at least OneWay), or use classic Binding. This workaround could be mentioned as a temporary limitation for the first release.
19 remaining items
[-]Loading, Loaded & Unloaded events are called too early[/-][+]`Loading`, `Loaded` & `Unloaded` events are called too early[/+]Youssef1313 commentedon Dec 2, 2023
We'll need to revisit this workaround:
uno/src/Uno.UI/Microsoft/UI/Xaml/Controls/TabView/TabView.cs
Lines 600 to 601 in 69b64c9
Youssef1313 commentedon Dec 4, 2023
ContentControlspecifically seems to be a bit special.It looks like when
Contentis set, it's not immediately added as a child (the comment in WinUI code says this is done "later".Then, for some reason,
fIsLiveis set to false which may have an effect onLoadedevent.In the case of Uno, setting
ContentControl.Contentwill immediately add the child.Youssef1313 commentedon Dec 4, 2023
Also note that
UserControlin WinUI is NOTContentControl, while in Uno it's aContentControl.If we aligned
ContentControlbehavior with WinUI, we will have to verifyUserControls behavior as well on WinUI and exclude them from that special behavior until the inheritance is fixed.Youssef1313 commentedon Dec 4, 2023
Using the above code, the button will get "Loaded" but not "Loading".
Note that if
ArrangeOverrideis removed, it will get both. This is becauseArrangewill attempt to measure if it detects the element wasn't measured.Youssef1313 commentedon Dec 4, 2023
Another interesting case:
The order of events is:
But the end state of btn is
IsLoaded = true.KWodarczyk commentedon Sep 16, 2024
I have also observed that all If I have multiple pages in my application their "Loaded" event if fired without event going to the page. Not sure if this is related but I need to figure out how to make "Loaded" event fire only when page is accessed any ideas ?
MartinZikmund commentedon Sep 17, 2024
That is certainly odd, which platform are you observing this on? Can you create a repro and post as a separate issue please?
MartinZikmund commentedon Jul 17, 2025
Works correctly in Skia targets, closing
jeanplevesque commentedon Jul 17, 2025
Does that mean native renderers are out of support? @MartinZikmund
github-actions commentedon May 4, 2026
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.