Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
'Declaration Public Event Loaded As RoutedEventHandler 'Usage Dim instance As FrameworkElement Dim handler As RoutedEventHandler AddHandler instance.Loaded, handler
/** @event */ public void add_Loaded (RoutedEventHandler value) /** @event */ public void remove_Loaded (RoutedEventHandler value)
In JScript, you can handle the events defined by a class, but you cannot define your own.
Loaded is usually the last event raised in an element initialization sequence. It will always be raised after Initialized. Whether you choose to handle Loaded or Initialized depends on your requirements. If you do not need to read element properties, intend to reset properties, and do not need any layout information, Initialized might be the better event to act upon. If you need all properties of the element to be available, and you will be setting properties that are likely to reset the layout, Loaded might be the better event to act upon. Be careful of reentrancy if your handler resets any properties that are interpreted by the layout system to mean that a new layout pass is required. (You might need to check the FrameworkPropertyMetadata values on the property if you are unsure of which properties can require a new layout pass if they are changed.)
Direct routed events do not follow a route, they are only handled within the same element on which they are raised. Direct routed events do support other routed event behavior: they support an accessible handlers collection, and can be used as an EventTrigger in a style.
Loaded and Unloaded might both be raised on controls as a result of user-initiated system theme changes. A theme change causes an invalidation of the control template and the contained visual tree, which in turn causes the entire control to unload and reload. Therefore Loaded cannot be assumed to occur only when a page is first loaded through navigation to the page.
This example shows how handle the FrameworkElement.Loaded event, and an appropriate scenario for handling that event. The handler creates a Button when the page loads .
The following example uses Extensible Application Markup Language (XAML) together with a code-behind file.
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SDKSample.FELoaded" Loaded="OnLoad" Name="root" > </StackPanel>
Public Sub OnLoad(ByVal sender As Object, ByVal e As RoutedEventArgs) Dim b1 As Button = New Button() b1.Content = "New Button" root.Children.Add(b1) b1.Height = 25 b1.Width = 200 b1.HorizontalAlignment = HorizontalAlignment.Left End Sub
For the complete sample, see Loaded Event Sample.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.