question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OnLoaded event calling again

See original GitHub issue

I’m working with UWP with WinUI 2.5 prerelease and have noticed a strange behavior which doesn’t happen in WPF. So i’m using a TabView control and loading a Page in it. Every time a new tab is created, a new page is loaded in it (nothing fancy).

Now, I have some OnLoaded events on my pages. so when a new tab is created and page is loaded, the OnLoad event is called (as it should) but now when i switch back to other tab and switch again to current page the OnLoaded event is called again. WHY ?

MainPage with TabView

<Page
    x:Class="TestUWPApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TestUWPApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="using:Microsoft.UI.Xaml.Controls"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <controls:TabView x:Name="MainTabView">
            <controls:TabView.TabItems>
                <controls:TabViewItem Header="Intelliventory"
                                      IsClosable="False" CanDrag="False">
                    <controls:TabViewItem.IconSource>
                        <controls:SymbolIconSource Symbol="Home" />
                    </controls:TabViewItem.IconSource>
                    <Frame SourcePageType="local:Page2" />
                </controls:TabViewItem>
                <controls:TabViewItem Header="Intelliventory"
                                      IsClosable="False" CanDrag="False">
                    <controls:TabViewItem.IconSource>
                        <controls:SymbolIconSource Symbol="Home" />
                    </controls:TabViewItem.IconSource>
                    <Frame SourcePageType="local:Page3" />
                </controls:TabViewItem>
            </controls:TabView.TabItems>
        </controls:TabView>
    </Grid>
</Page>  

Page3 that has an OnLoaded event

namespace TestUWPApp
{

    public sealed partial class Page3 : Page
    {
        public Page3()
        {
            this.InitializeComponent();
        }

        private void Page3_OnLoaded(object sender, RoutedEventArgs e)
        {
            //This event is called every time tab is switched
        }
    }
} 

Every time selected tab is changed to Page3 tab the onLoaded event is called. That should just be called once when first time the tab was switched and Page was loaded.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
StephenLPeterscommented, Jul 1, 2020

I think there is a little confusion about what loaded means. In UWP it does not indicate that the content was loaded into memory, it indicates that the item was added to the visual tree. The UWP TabView adds the contents associated with the selected TabViewItem to the visual tree when the selection changes so we do expect the loaded event to fire.

1reaction
StephenLPeterscommented, Jun 29, 2020

If you have more questions feel free to ask here even thought he issue is closed 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I run a function onload and then call it again from ...
How do I run a function onload and then call it again from an onclick event ... $(document).ready(function() { "use strict"; var $rows_views...
Read more >
onload Event
The onload event occurs when an object has been loaded. onload is most often used within the <body> element to execute a script...
Read more >
Window: load event - Web APIs - MDN Web Docs - Mozilla
The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images.
Read more >
Events, Onload Event and JQuery
onload = myOnLoad , but the function is assigned to the variable window.onload and called later when the onLoad event is raised. To...
Read more >
JavaScript Tutorial For Beginners #41 - Window onLoad Event
So in this JavaScript tutorial for beginners, I want to show you another kind of JavaScript event - the Window. onload event !...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found