Nasıl yapılır: Yüklü bir Olayı İşleme
Bu örnek FrameworkElement.Loaded , olayın nasıl işleneceğini ve bu olayı işlemek için uygun bir senaryoyu gösterir. İşleyici, Button sayfa yüklendiğinde bir oluşturur.
Örnek
Aşağıdaki örnek, bir arka plan kod dosyası ile birlikte Extensible Application Markup Language (XAML) kullanır.
<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