Procedura: gestire un evento caricato
In questo esempio viene illustrato come gestire l'evento FrameworkElement.Loaded e viene descritto uno scenario adatto per la gestione di tale evento. Il gestore crea Button quando viene caricata la pagina.
Esempio
Nell'esempio riportato di seguito viene utilizzato Extensible Application Markup Language (XAML) con un file code-behind.
<StackPanel
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SDKSample.FELoaded"
Loaded="OnLoad"
Name="root"
>
</StackPanel>
Private 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
void OnLoad(object sender, RoutedEventArgs e)
{
Button b1 = new Button();
b1.Content = "New Button";
root.Children.Add(b1);
b1.Height = 25;
b1.Width = 200;
b1.HorizontalAlignment = HorizontalAlignment.Left;
}
Vedere anche
Riferimenti
Concetti
Eventi di durata degli oggetti
Cenni preliminari sugli eventi indirizzati