如何:處理 Loaded 事件
此範例顯示如何處理 FrameworkElement.Loaded 事件,以及處理該事件的適當案例。 載入頁面時,處理常式會建立一個 Button。
範例
以下範例使用了 Extensible Application Markup Language (XAML) 與後端程式碼檔案一起進行作業。
<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>
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;
}
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