Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7979811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:52:38+00:00 2026-06-04T09:52:38+00:00

If I attach a handler to the Loaded event of an element (no matter

  • 0

If I attach a handler to the Loaded event of an element (no matter if it is in the VS designer or in the code), it sets the IsLoaded property to true.

For instance, I have a TabControl with two TabItems. There is a button on each TabItem. The first TabItem is the default item (selected when my window is shown). The Button on the second TabItem has attached the Loaded event. In this case, the button on the first TabItem has IsLoaded set to true and the button on the second TabItem should be set to false but it is set to true.

When I unset the Loaded event it works as expected – the first button has IsLoaded true, the second has false.

Is this a wpf bug or am I doing something wrong?

EDIT:

See an example.

This code causes the IsLoaded property of btn2 set to True (Note: the btn2_Loaded method is empty).

XAML:

    <Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TabControl>
            <TabItem Header="Tab1">
                <Button x:Name="btn1" Click="btn1_Click" />
            </TabItem>

            <TabItem Header="Tab2">
                <Button x:Name="btn2" Loaded="btn2_Loaded" />
            </TabItem>
        </TabControl>
    </Grid>
</Window>

C#:

    private void btn1_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show(this.btn2.IsLoaded.ToString());
    }

Start the application and just click the btn1.

Now remove the Loaded handler:

            <TabItem Header="Tab2">
                <Button x:Name="btn2" />
            </TabItem>

Start the application again and click the btn1.

Now the IsLoaded is False! Why is this happening? Attaching an event handler causes loading of the particular element?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:52:39+00:00Added an answer on June 4, 2026 at 9:52 am

    This is neither a bug in WPF nor are you doing something wrong. The MSDN page on Object Lifetime Events says that

    The Loaded event is raised before the final rendering, but after the
    layout system has calculated all necessary values for rendering.

    You can not make any more precise assumption on when exactly Loaded is called. In your case i guess WPF delays loading of the non-visible (i.e. not yet rendered) elements, unless a Loaded handler is attached. It is just free to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to attach a handler to the resize event in one
I'm trying to attach an event handler to the load event of a link
When I try to attach event handler functions with parameters like : myhandle.onclick =
I need to attach an event handler to an object, and I placed this
How do I attach a handler to the click event of a link, which
I attach a click handler to a button on my page. Is there anyway
So, what I want is basically to attach a javascript handler to a form,
If I use for example a mousemove event handler on a div and check
I have an unordered list that is being loaded from an external file using
I am trying to attach some handlers to each TreeViewItem as they are loaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.