■ Application 클래스의 RequestedTheme 속성을 사용해 테마를 설정하는 방법을 보여준다.
▶ App.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<Application x:Class="TestProject.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RequestedTheme="Dark"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Common/StandardStyle.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> |
▶ App.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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
using System; using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; using Windows.Foundation; using Windows.Graphics.Display; using Windows.UI.ViewManagement; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace TestProject { /// <summary> /// 앱 /// </summary> sealed partial class App : Application { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - App() /// <summary> /// 생성자 /// </summary> public App() { InitializeComponent(); Suspending += Application_Suspending; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected //////////////////////////////////////////////////////////////////////////////// Function #region 런치시 처리하기 - OnLaunched(e) /// <summary> /// 런치시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { Frame rootFrame = Window.Current.Content as Frame; if(rootFrame == null) { rootFrame = new Frame(); Window.Current.Content = rootFrame; } if(rootFrame.Content == null) { if(!rootFrame.Navigate(typeof(MainPage), e.Arguments)) { throw new Exception("초기 페이지 생성시 실패했습니다."); } } SetWindowSize(800, 600); Window.Current.Activate(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 애플리케이션 실행 보류시 처리하기 - Application_Suspending(sender, e) /// <summary> /// 애플리케이션 실행 보류시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Application_Suspending(object sender, SuspendingEventArgs e) { SuspendingDeferral suspendingDeferral = e.SuspendingOperation.GetDeferral(); suspendingDeferral.Complete(); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 윈도우 크기 설정하기 - SetWindowSize(width, height) /// <summary> /// 윈도우 크기 설정하기 /// </summary> /// <param name="width">너비</param> /// <param name="height">높이</param> private void SetWindowSize(double width, double height) { float logicalDPI = DisplayInformation.GetForCurrentView().LogicalDpi; ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; Size desiredSize = new Size((width * 96.0f / logicalDPI), (height * 96.0f / logicalDPI)); ApplicationView.PreferredLaunchViewSize = desiredSize; } #endregion } } |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<Page x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontFamily="나눔고딕코딩" FontSize="16"> <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Yellow" FontSize="96" FontStyle="Italic" Text="Hello, World!" /> </Grid> </Page> |
▶ MainPage.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 |
using Windows.UI.Xaml.Controls; namespace TestProject { /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); } #endregion } } |