<Window x:Class="WPF_HelloWindows.Window1” xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Hello WPF" Height="150" Width="250"> <Grid Background="AntiqueWhite" > <Label x:Name="label1" VerticalAlignment="Center" HorizontalAlignment="Center">Hello, WPF!</Label> </Grid> </Window>
Application
object and settings
<Application x:Class="HelloWPF.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> </Application.Resources> </Application>
StartupUri
indicates XAML file to be executed first
when app starts
App.xaml
, which handles application-level events
Startup
event is triggered
namespace HelloWPF { public partial class App : Application { private void Application_Startup(object sender, StartupEventArgs e) { if (e.Args.Length == 1) MessageBox.Show("Opening file: " + e.Args[0]); } } }
<Window>
tags
<Window x:Class="HelloWPF.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"> <Grid> </Grid> </Window>
<Grid>
is a layout container that places
widgets in rows and columns
System.Windows.Window
namespace HelloWPF { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } }
Main()
public static void Main() { HelloWpf.App app = new HelloWpf.App(); app.InitializeComponent(); app.Run(); }
InitializeComponent()
and all controls
internal System.Windows.Controls.Label label1;