■ ApplicationView 클래스 : PreferredLaunchViewSize 정적 속성과 TryResizeView 메소드를 사용해 메인 윈도우 크기 설정하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


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;

 

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("초기 페이지 생성시 실패했습니다.");

                }

            }

 

            #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

        //////////////////////////////////////////////////////////////////////////////// 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

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요