App.xaml은 어플리케이션의 선언부 시작점이다.
새로운 WPF 어플리케이션 프로젝트를 시작할 때 App.xaml(XAML)과 App.xaml.cs(CodeBehind) 파일을 자동으로 생성한다.
App.xaml.cs는 Application클래스를 상속받는다.
이 클래스는 어플리케이션 시작, 예기치 않은 예외 발생 등 중요한 어플리케이션 이벤트들을 주시하는 곳이다.
StartUri 속성은 어플리케이션이 실행될 때, 어떤 윈도우 혹은 페이지를 시작하는지 정의하는 부분이다.
StartUri를 Startup 이벤트 구독을 통해 대체 가능하다.
<Application x:Class="WpfTutorialSamples.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">
<Application.Resources></Application.Resources>
</Application>
using System;
using System.Collections.Generic;
using System.Windows;
namespace WpfTutorialSamples
{
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
MainWindow wnd = new MainWindow();
wnd.Title = "Something else";
wnd.Show();
}
}
}
위와 같은 이벤트를 통해 더 많은 인자들을 수집할 수 있으며, 특정 기능을 ON/OFF하는 토글링 옵션등에 사용할 수 있다. 또한, 처리하고자 하는 정보를 수집하기 위하여 인자 리스트를 루프로 돌려 전달할 수 있는 등 다양한 역할을 수행할 수 있다.