728x90
반응형
728x170
▶ App.xaml
<Application x:Class="TestProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
728x90
▶ App.xaml.cs
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;
using Windows.UI.Xaml.Navigation;
namespace TestProject
{
/// <summary>
/// 앱
/// </summary>
sealed partial class App : Application
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - App()
/// <summary>
/// 생성자
/// </summary>
public App()
{
InitializeComponent();
Suspending += Application_Suspending;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Protected
#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();
rootFrame.NavigationFailed += rootFrame_NavigationFailed;
if(e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
}
Window.Current.Content = rootFrame;
}
if(e.PrelaunchActivated == false)
{
if(rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
Window.Current.Activate();
}
#region 윈도우 크기를 설정한다.
double width = 800d;
double height = 600d;
double dpi = (double)DisplayInformation.GetForCurrentView().LogicalDpi;
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
Size windowSize = new Size(width * 96d / dpi, height * 96d / dpi);
ApplicationView.PreferredLaunchViewSize = windowSize;
Window.Current.Activate();
ApplicationView.GetForCurrentView().TryResizeView(windowSize);
#endregion
}
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 애플리케이션 정지시 처리하기 - Application_Suspending(sender, e)
/// <summary>
/// 애플리케이션 정지시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Application_Suspending(object sender, SuspendingEventArgs e)
{
SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
deferral.Complete();
}
#endregion
#region 루트 프레임 네비게이션 실패시 처리하기 - rootFrame_NavigationFailed(sender, e)
/// <summary>
/// 루트 프레임 네비게이션 실패시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void rootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception($"페이지 로드를 실패했습니다 : {e.SourcePageType.FullName}");
}
#endregion
}
}
300x250
▶ MainPage.xaml
<Page x:Class="TestProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:winui="using:Microsoft.UI.Xaml.Controls"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
</Grid>
</Page>
▶ MainPage.xaml.cs
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
}
}
※ 패키지 설치 : Microsoft.UI.Xaml
1. Visual Studio를 실행한다.
2. [도구] / [NuGet 패키지 관리자] / [패키지 관리자 콘솔] 메뉴를 실행한다.
3. 아래 스크립트를 실행한다.
Install-Package Microsoft.UI.Xaml
728x90
반응형
그리드형(광고전용)
'C# > UWP' 카테고리의 다른 글
[C#/UWP] CoreApplication 클래스 : GetCurrentView 정적 메소드를 사용해 애플리케이션 활성 뷰 구하기 (0) | 2021.05.03 |
---|---|
[C#/UWP] KeyboardCapabilities 클래스 : KeyboardPresent 속성을 사용해 키보드 연결 여부 구하기 (0) | 2021.05.03 |
[C#/UWP] Window 클래스 : Current 정적 속성을 사용해 현재 활성화 윈도우 구하기 (0) | 2021.05.03 |
[C#/UWP] ElementSoundPlayer 클래스 : SpatialAudioMode 정적 속성을 사용해 공간 오디오 설정하기 (0) | 2021.05.03 |
[C#/UWP] ElementSoundPlayer 클래스 : State 정적 속성을 사용해 컨트롤의 소리 재생 여부 설정하기 (0) | 2021.05.03 |
[C#/UWP] WinUI 앱 사용하기 (0) | 2021.05.01 |
[C#/UWP] 누겟 설치 : Microsoft.UI.Xaml (0) | 2021.05.01 |
[C#/UWP] StackPanel 클래스 사용하기 (0) | 2019.02.27 |
[C#/UWP] StackPanel 클래스 사용하기 (0) | 2019.02.27 |
[C#/UWP] Ellipse 클래스 사용하기 (0) | 2019.02.27 |
[C#/UWP] Border 클래스 사용하기 (0) | 2019.02.27 |
댓글을 달아 주세요