title: WPF, Loaded event, IsLoaded property
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>When I unset the Loaded event it works as expected - the first button has IsLoaded true, the second has false.</p>
  
  <p>Is this a wpf bug or am I doing something wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>See an example.</p>
  
  <p>This code causes the IsLoaded property of btn2 set to True (Note: the btn2_Loaded method is empty).</p>
  
  <p>XAML:</p>
  
  <pre><code>    &lt;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"&gt;
      &lt;Grid&gt;
          &lt;TabControl&gt;
              &lt;TabItem Header="Tab1"&gt;
                  &lt;Button x:Name="btn1" Click="btn1_Click" /&gt;
              &lt;/TabItem&gt;
  
              &lt;TabItem Header="Tab2"&gt;
                  &lt;Button x:Name="btn2" Loaded="btn2_Loaded" /&gt;
              &lt;/TabItem&gt;
          &lt;/TabControl&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>    private void btn1_Click(object sender, RoutedEventArgs e)
      {
          MessageBox.Show(this.btn2.IsLoaded.ToString());
      }
  </code></pre>
  
  <p>Start the application and just click the btn1.</p>
  
  <p>Now remove the Loaded handler:</p>
  
  <pre><code>            &lt;TabItem Header="Tab2"&gt;
                  &lt;Button x:Name="btn2" /&gt;
              &lt;/TabItem&gt;
  </code></pre>
  
  <p>Start the application again and click the btn1.</p>
  
  <p>Now the IsLoaded is False! Why is this happening? Attaching an event handler causes loading of the particular element?</p>