■ Application 클래스의 Activated/Deactivated 이벤트를 사용해 애플리케이션 활성화/비활성화시 처리하는 방법을 보여준다.
▶ MainApplication.xaml
1 2 3 4 5 6 7 8 9 |
<Application x:Class="TestProject.MainApplication" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml" Activated="Application_Activated" Deactivated="Application_Deactivated"> </Application> |
▶ MainApplication.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using System; using System.Windows; namespace TestProject { /// <summary> /// 메인 애플리케이션 /// </summary> public partial class MainApplication : Application { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 애플리케이션 활성화시 처리하기 - Application_Activated(sender, e) /// <summary> /// 애플리케이션 활성화시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Application_Activated(object sender, EventArgs e) { MainWindow window = MainWindow as MainWindow; window.Content = "Application activated."; } #endregion #region 애플리케이션 비활성화시 처리하기 - Application_Deactivated(sender, e) /// <summary> /// 애플리케이션 비활성화시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Application_Deactivated(object sender, EventArgs e) { MainWindow window = MainWindow as MainWindow; window.Content = "Application deactivated."; } #endregion } } |