첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
0.03MB

▶ NotifyType.cs

namespace TestProject
{
    /// <summary>
    /// 통지 타입
    /// </summary>
    public enum NotifyType
    {
        /// <summary>
        /// 상태 메시지
        /// </summary>
        StatusMessage,

        /// <summary>
        /// 에러 메시지
        /// </summary>
        ErrorMessage
    };
}

 

728x90

 

▶ Scenario.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 시나리오
    /// </summary>
    public class Scenario
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 제목 - Title

        /// <summary>
        /// 제목
        /// </summary>
        public string Title { get; set; }

        #endregion
        #region 클래스 타입 - ClassType

        /// <summary>
        /// 클래스 타입
        /// </summary>
        public Type ClassType { get; set; }

        #endregion
    }
}

 

300x250

 

▶ SamplePage1.xaml

<Page x:Class="TestProject.SamplePage1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid Name="RootGrid"
            Margin="10">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*"    />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0"
                Margin="0 0 0 10">
                <TextBlock
                    Style="{StaticResource SampleHeaderTextStyle}"
                    Text="설명 :" />
                <TextBlock
                    Style="{StaticResource ScenarioDescriptionTextStyle}"
                    TextWrapping="Wrap">
하드웨어 뒤로가기 버튼, 전역 탐색바, 단축키 및 제목 표시줄 UI와 같은 시스템 자산을 사용하여 뒤로가기 탐색을 활성화하는 방법
                </TextBlock>
            </StackPanel>
            <ScrollViewer Grid.Row="1"
                VerticalScrollMode="Auto"
                VerticalScrollBarVisibility="Auto">
                <StackPanel
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top">
                    <CheckBox Name="checkBox"
                        Content="제목 표시줄 뒤로가기 버튼 활성화"
                        Checked="checkBox_Checked"
                        Unchecked="checkBox_Checked" />
                    <Button
                        Content="샘플 페이지 2로 이동"
                        Click="button_Click" />
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </Grid>
</Page>

 

▶ SamplePage1.xaml.cs

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace TestProject
{
    /// <summary>
    /// 샘플 페이지 1
    /// </summary>
    public sealed partial class SamplePage1 : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 체크 여부
        /// </summary>
        private bool isChecked = false;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - SamplePage1()

        /// <summary>
        /// 생성자
        /// </summary>
        public SamplePage1()
        {
            InitializeComponent();

            NavigationCacheMode = NavigationCacheMode.Required;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 체크 박스 체크시 처리하기 - checkBox_Checked(sender, e)

        /// <summary>
        /// 체크 박스 체크시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void checkBox_Checked(object sender, RoutedEventArgs e)
        {
            this.isChecked = !this.isChecked;
        }

        #endregion
        #region 버튼 클릭시 처리하기 - button_Click(sender, e)

        /// <summary>
        /// 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void button_Click(object sender, RoutedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            rootFrame.Navigate(typeof(SamplePage2), this.isChecked);
        }

        #endregion
    }
}

 

▶ SamplePage2.xaml

<Page x:Class="TestProject.SamplePage2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid Name="RootGrid"
            Margin="10">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*"    />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0"
                Margin="0 0 0 10">
                <TextBlock
                    Style="{StaticResource SampleHeaderTextStyle}"
                    Text="샘플 페이지 2" />
                <TextBlock
                    Style="{StaticResource ScenarioDescriptionTextStyle}"
                    TextWrapping="Wrap">
기본 페이지로 다시 이동하는 유일한 방법은 아래 나열된 시스템 백 어포던스 중 하나를 사용하는 것입니다.
                </TextBlock>
            </StackPanel>
            <ScrollViewer Grid.Row="1"
                VerticalScrollMode="Auto"
                VerticalScrollBarVisibility="Auto">
                <StackPanel
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top">
                    <TextBlock Text="1. 하드웨어 뒤로가기(전화를 사용하는 경우)" />
                    <TextBlock
                        TextWrapping="Wrap"
                        Text="2. 전역 탐색 표시줄 뒤로가기(태블릿 모드에 있는 경우)" />
                    <TextBlock
                        TextWrapping="Wrap"
                        Text="3. Windows 키 + 백스페이스 키(키보드가 연결된 경우)" />
                    <TextBlock
                        TextWrapping="Wrap"
                        Text="4. 제목 표시줄 뒤로가기(데스크탑 모드에 있는 경우)" />
                    <TextBlock
                        TextWrapping="Wrap"
                        Text="5. 'Cortana Go Back'이라고 말하세요(Hololens를 사용 중인 경우)." />
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </Grid>
</Page>

 

▶ SamplePage2.xaml.cs

using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace TestProject
{
    /// <summary>
    /// 샘플 페이지 2
    /// </summary>
    public sealed partial class SamplePage2 : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - SamplePage2()

        /// <summary>
        /// 생성자
        /// </summary>
        public SamplePage2()
        {
            InitializeComponent();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Proptected

        #region 탐색되는 경우 처리하기 - OnNavigatedTo(e)

        /// <summary>
        /// 탐색되는 경우 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            bool isChecked = false;

            if((bool)e.Parameter)
            {
                isChecked = true;
            }

            Frame rootFrame = Window.Current.Content as Frame;

            if(rootFrame.CanGoBack && isChecked)
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            }
            else
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            }
        }

        #endregion
    }
}

 

▶ 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:local="using:TestProject"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"    />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0"
            Orientation="Horizontal">
            <Border Background="{ThemeResource SystemControlBackgroundChromeMediumBrush}">
                <ToggleButton
                    Style="{StaticResource SymbolButton}"
                    VerticalAlignment="Center"
                    Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
                    Click="paneToggleButton_Click">
                    <ToggleButton.Content>
                        <FontIcon
                            FontFamily="Segoe MDL2 Assets"
                            Glyph="&#xE700;" />
                    </ToggleButton.Content>
                </ToggleButton>
            </Border>
            <Image
                VerticalAlignment="Center"
                Margin="5 5 0 0"
                AutomationProperties.AccessibilityView="Raw"
                Stretch="None"
                Source="IMAGE/windows-sdk.png" />
            <TextBlock
                Style="{StaticResource TagLineTextStyle}"
                VerticalAlignment="Center"
                Margin="5 0 0 0"
                Text="유니버셜 윈도우즈 플랫폼" />
        </StackPanel>
        <SplitView Name="splitView" Grid.Row="1"
            DisplayMode="Inline"
            IsPaneOpen="True">
            <SplitView.Pane>
                <RelativePanel Margin="10 0 0 0">
                    <TextBlock Name="sampleTitle"
                        Style="{StaticResource SampleHeaderTextStyle}"
                        Margin="0 10 0 0"
                        TextWrapping="Wrap"
                        Text="C# 달력 예제" />
                    <ListBox Name="listBox"
                        RelativePanel.Below="sampleTitle"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        Margin="0 10 0 0"
                        BorderThickness="0"
                        Background="Transparent"
                        SelectionMode="Single"
                        SelectionChanged="listBox_SelectionChanged">
                        <ListBox.ItemTemplate>
                            <DataTemplate x:DataType="local:Scenario">
                                <TextBlock Text="{x:Bind Title}" />
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </RelativePanel>
            </SplitView.Pane>
            <RelativePanel>
                <Frame Name="frame"
                    RelativePanel.AlignLeftWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"
                    RelativePanel.AlignTopWithPanel="True"
                    RelativePanel.Above="statusStackPanel"
                    Margin="5" />
                <StackPanel Name="statusStackPanel"
                    Orientation="Vertical"
                    RelativePanel.AlignLeftWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"
                    RelativePanel.AlignBottomWithPanel="True">
                    <TextBlock
                        Margin="10 0 0 10"
                        TextWrapping="Wrap"
                        Text="상태 : " />
                    <Border Name="statusBorder"
                        Margin="0 0 0 0">
                        <ScrollViewer
                            VerticalScrollMode="Auto"
                            VerticalScrollBarVisibility="Auto"
                            MaxHeight="200">
                            <TextBlock Name="statusTextBlock"
                                AutomationProperties.LiveSetting="Assertive"
                                Margin="10 10 10 20"
                                MaxWidth="{Binding ElementName=Splitter, Path=ActualWidth}"
                                TextWrapping="Wrap"
                                FontWeight="Bold" />
                        </ScrollViewer>
                    </Border>
                </StackPanel>
            </RelativePanel>
        </SplitView>
    </Grid>
</Page>

 

▶ MainPage.xaml.cs

using System.Collections.Generic;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace TestProject
{
    /// <summary>
    /// 메인 페이지
    /// </summary>
    public sealed partial class MainPage : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 시나리오 리스트
        /// </summary>
        private List<Scenario> scenarioList = new List<Scenario>
        {
            new Scenario() { Title = "BackRequested 이벤트 구독하기", ClassType = typeof(SamplePage1) }
        };

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainPage()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainPage()
        {
            InitializeComponent();

            #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
            #region 윈도우 제목을 설정한다.

            ApplicationView.GetForCurrentView().Title = "제목 표시줄 뒤로가기 버튼 사용하기";

            #endregion

            NavigationCacheMode = NavigationCacheMode.Required;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 탐색되는 경우 처리하기 - OnNavigatedTo(e)

        /// <summary>
        /// 탐색되는 경우 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.listBox.ItemsSource = this.scenarioList;

            if(Window.Current.Bounds.Width < 640)
            {
                this.listBox.SelectedIndex = -1;
            }
            else
            {
                this.listBox.SelectedIndex = 0;
            }

            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 창 토글 버튼 클릭시 처리하기 - paneToggleButton_Click(sender, e)

        /// <summary>
        /// 창 토글 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void paneToggleButton_Click(object sender, RoutedEventArgs e)
        {
            this.splitView.IsPaneOpen = !splitView.IsPaneOpen;
        }

        #endregion
        #region 리스트 박스 선택 변경시 처리하기 - listBox_SelectionChanged(sender, e)

        /// <summary>
        /// 리스트 박스 선택 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ShowStatusMessage(string.Empty, NotifyType.StatusMessage);

            ListBox listBox = sender as ListBox;

            Scenario scenario = listBox.SelectedItem as Scenario;

            if(scenario != null)
            {
                this.frame.Navigate(scenario.ClassType);

                if(Window.Current.Bounds.Width < 640)
                {
                    this.splitView.IsPaneOpen = false;
                }
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 상태 메시지 표시하기 - ShowStatusMessage(message, notifiyType)

        /// <summary>
        /// 상태 메시지 표시하기
        /// </summary>
        /// <param name="message">메시지</param>
        /// <param name="notifiyType">통지 타입</param>
        private void ShowStatusMessage(string message, NotifyType notifiyType)
        {
            switch(notifiyType)
            {
                case NotifyType.StatusMessage : this.statusBorder.Background = new SolidColorBrush(Colors.Green); break;
                case NotifyType.ErrorMessage  : this.statusBorder.Background = new SolidColorBrush(Colors.Red  ); break;
            }

            this.statusTextBlock.Text = message;

            this.statusBorder.Visibility = (this.statusTextBlock.Text != string.Empty) ? Visibility.Visible : Visibility.Collapsed;

            if(this.statusTextBlock.Text != string.Empty)
            {
                this.statusBorder.Visibility = Visibility.Visible;

                this.statusStackPanel.Visibility = Visibility.Visible;
            }
            else
            {
                this.statusBorder.Visibility = Visibility.Collapsed;

                this.statusStackPanel.Visibility = Visibility.Collapsed;
            }
        }

        #endregion
    }
}

 

▶ 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"
    RequestedTheme="Dark">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/STYLE/Style.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

 

▶ App.xaml.cs

using System;
using System.Diagnostics;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Globalization;
using Windows.UI.Core;
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)
        {
#if DEBUG
            if(Debugger.IsAttached)
            {
                DebugSettings.EnableFrameRateCounter = false;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            if(rootFrame == null)
            {
                rootFrame = new Frame();

                rootFrame.Language = ApplicationLanguages.Languages[0];

                rootFrame.NavigationFailed += rootFrame_NavigationFailed;

                if(e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                }

                Window.Current.Content = rootFrame;
            }

            if(rootFrame.Content == null)
            {
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }

            SystemNavigationManager.GetForCurrentView().BackRequested += SystemNavigationManager_BackRequested;

            Window.Current.Activate();
        }

        #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
        #region 시스템 탐색 관리자 뒤로가기 요청시 처리하기 - SystemNavigationManager_BackRequested(sender, e)

        /// <summary>
        /// 시스템 탐색 관리자 뒤로가기 요청시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void SystemNavigationManager_BackRequested(object sender, BackRequestedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            if(rootFrame == null)
            {
                return;
            }

            if(rootFrame.CanGoBack && e.Handled == false)
            {
                e.Handled = true;

                rootFrame.GoBack();
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요