[C#][WPF] App

LimJaeJun·2024년 3월 19일
0

WPF

목록 보기
6/12

App.xaml

App.xaml은 어플리케이션의 선언부 시작점이다.
새로운 WPF 어플리케이션 프로젝트를 시작할 때 App.xaml(XAML)과 App.xaml.cs(CodeBehind) 파일을 자동으로 생성한다.

App.xaml.cs는 Application클래스를 상속받는다.
이 클래스는 어플리케이션 시작, 예기치 않은 예외 발생 등 중요한 어플리케이션 이벤트들을 주시하는 곳이다.

App.xaml 구조

StartUri 속성은 어플리케이션이 실행될 때, 어떤 윈도우 혹은 페이지를 시작하는지 정의하는 부분이다.

App.xaml.cs 구조

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하는 토글링 옵션등에 사용할 수 있다. 또한, 처리하고자 하는 정보를 수집하기 위하여 인자 리스트를 루프로 돌려 전달할 수 있는 등 다양한 역할을 수행할 수 있다.

참고 링크

https://wpf-tutorial.com/ko/11/wpf-application/wpf%EC%97%90%EC%84%9C%EC%9D%98-%EB%AA%85%EB%A0%B9%EC%A4%84-%ED%8C%8C%EB%9D%BC%EB%AF%B8%ED%84%B0/

profile
Dreams Come True

0개의 댓글