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

728x90
반응형
728x170

TestProject.zip
0.15MB

▶ ControlInfoDocumentLink.cs

namespace TestProject
{
    /// <summary>
    /// 컨트롤 정보 문서 링크
    /// </summary>
    public class ControlInfoDocumentLink
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 제목 - Title

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

        #endregion
        #region URI - URI

        /// <summary>
        /// URI
        /// </summary>
        public string URI { get; private set; }

        #endregion

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

        #region 생성자 - ControlInfoDocumentLink(title, uri)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="title">제목</param>
        /// <param name="uri">URI</param>
        public ControlInfoDocumentLink(string title, string uri)
        {
            Title = title;
            URI   = uri;
        }

        #endregion
    }
}

 

728x90

 

▶ ControlInfoDataItem.cs

using System.Collections.ObjectModel;

namespace TestProject
{
    /// <summary>
    /// 컨트롤 정보 데이터 항목
    /// </summary>
    public class ControlInfoDataItem
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 고유 ID - UniqueID

        /// <summary>
        /// 고유 ID
        /// </summary>
        public string UniqueID { get; private set; }

        #endregion
        #region 제목 - Title

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

        #endregion
        #region 하위 제목 - Subtitle

        /// <summary>
        /// 하위 제목
        /// </summary>
        public string Subtitle { get; private set; }

        #endregion
        #region 설명 - Description

        /// <summary>
        /// 설명
        /// </summary>
        public string Description { get; private set; }

        #endregion
        #region 이미지 경로 - ImagePath

        /// <summary>
        /// 이미지 경로
        /// </summary>
        public string ImagePath { get; private set; }

        #endregion
        #region 배지 문자열 - BadgeString

        /// <summary>
        /// 배지 문자열
        /// </summary>
        public string BadgeString { get; private set; }

        #endregion
        #region 내용 - Content

        /// <summary>
        /// 내용
        /// </summary>
        public string Content { get; private set; }

        #endregion
        #region 신규 여부 - IsNew

        /// <summary>
        /// 신규 여부
        /// </summary>
        public bool IsNew { get; private set; }

        #endregion
        #region 업데이트 여부 - IsUpdated

        /// <summary>
        /// 업데이트 여부
        /// </summary>
        public bool IsUpdated { get; private set; }

        #endregion
        #region 미리보기 여부 - IsPreview

        /// <summary>
        /// 미리보기 여부
        /// </summary>
        public bool IsPreview { get; private set; }

        #endregion
        #region 문서 링크 컬렉션 - DocumentLinkCollection

        /// <summary>
        /// 문서 링크 컬렉션
        /// </summary>
        public ObservableCollection<ControlInfoDocumentLink> DocumentLinkCollection { get; private set; }

        #endregion
        #region 연결 컨트롤 컬렉션 - RelatedControlCollection

        /// <summary>
        /// 연결 컨트롤 컬렉션
        /// </summary>
        public ObservableCollection<string> RelatedControlCollection { get; private set; }

        #endregion

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

        #region 생성자 - ControlInfoDataItem(uniqueID, title, subtitle, imagePath, badgeString, description, content, isNew, isUpdated, isPreview)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="uniqueID">고유 ID</param>
        /// <param name="title">제목</param>
        /// <param name="subtitle">하위 제목</param>
        /// <param name="imagePath">이미지 경로</param>
        /// <param name="badgeString">배지 문자열</param>
        /// <param name="description">설명</param>
        /// <param name="content">내용</param>
        /// <param name="isNew">신규 여부</param>
        /// <param name="isUpdated">업데이트 여부</param>
        /// <param name="isPreview">미리보기 여부</param>
        public ControlInfoDataItem
        (
            string uniqueID,
            string title,
            string subtitle,
            string imagePath,
            string badgeString,
            string description,
            string content,
            bool   isNew,
            bool   isUpdated,
            bool   isPreview
        )
        {
            UniqueID                 = uniqueID;
            Title                    = title;
            Subtitle                 = subtitle;
            ImagePath                = imagePath;
            BadgeString              = badgeString;
            Description              = description;
            Content                  = content;
            IsNew                    = isNew;
            IsUpdated                = isUpdated;
            IsPreview                = isPreview;
            DocumentLinkCollection   = new ObservableCollection<ControlInfoDocumentLink>();
            RelatedControlCollection = new ObservableCollection<string>();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 문자열 구하기 - ToString()

        /// <summary>
        /// 문자열 구하기
        /// </summary>
        /// <returns>문자열</returns>
        public override string ToString()
        {
            return Title;
        }

        #endregion
    }
}

 

300x250

 

▶ ControlInfoDataGroup.cs

using System.Collections.ObjectModel;

namespace TestProject
{
    /// <summary>
    /// 컨트롤 정보 데이터 그룹
    /// </summary>
    public class ControlInfoDataGroup
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 고유 ID - UniqueID

        /// <summary>
        /// 고유 ID
        /// </summary>
        public string UniqueID { get; private set; }

        #endregion
        #region 제목 - Title

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

        #endregion
        #region 하위 제목 - Subtitle

        /// <summary>
        /// 하위 제목
        /// </summary>
        public string Subtitle { get; private set; }

        #endregion
        #region 설명 - Description

        /// <summary>
        /// 설명
        /// </summary>
        public string Description { get; private set; }

        #endregion
        #region 이미지 경로 - ImagePath

        /// <summary>
        /// 이미지 경로
        /// </summary>
        public string ImagePath { get; private set; }

        #endregion
        #region 데이터 항목 컬렉션 - DataItemCollection

        /// <summary>
        /// 데이터 항목 컬렉션
        /// </summary>
        public ObservableCollection<ControlInfoDataItem> DataItemCollection { get; private set; }

        #endregion

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

        #region 생성자 - ControlInfoDataGroup(uniqueID, title, subtitle, imagePath, description)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="uniqueID">고유 ID</param>
        /// <param name="title">제목</param>
        /// <param name="subtitle">하위 제목</param>
        /// <param name="imagePath">이미지 경로</param>
        /// <param name="description">설명</param>
        public ControlInfoDataGroup(string uniqueID, string title, string subtitle, string imagePath, string description)
        {
            UniqueID           = uniqueID;
            Title              = title;
            Subtitle           = subtitle;
            Description        = description;
            ImagePath          = imagePath;
            DataItemCollection = new ObservableCollection<ControlInfoDataItem>();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 문자열 구하기 - ToString()

        /// <summary>
        /// 문자열 구하기
        /// </summary>
        /// <returns>문자열</returns>
        public override string ToString()
        {
            return Title;
        }

        #endregion
    }
}

 

▶ ControlInfoDataSource.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Data.Json;
using Windows.Storage;

namespace TestProject
{
    /// <summary>
    /// 컨트롤 정보 데이터 소스
    /// </summary>
    public sealed class ControlInfoDataSource
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 잠금 객체
        /// </summary>
        private static readonly object _lockObject = new object();

        /// <summary>
        /// 인스턴스
        /// </summary>
        private static ControlInfoDataSource _instance;

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Instance
        //////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 데이터 그룹 리스트
        /// </summary>
        private IList<ControlInfoDataGroup> dataGroupList = new List<ControlInfoDataGroup>();

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 인스턴스 - Instance

        /// <summary>
        /// 인스턴스
        /// </summary>
        public static ControlInfoDataSource Instance
        {
            get
            {
                return _instance;
            }
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Instance
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 데이터 그룹 리스트 - DataGroupList

        /// <summary>
        /// 데이터 그룹 리스트
        /// </summary>
        public IList<ControlInfoDataGroup> DataGroupList
        {
            get
            {
                return this.dataGroupList;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Static

        #region 생성자 - ControlInfoDataSource()

        /// <summary>
        /// 생성자
        /// </summary>
        static ControlInfoDataSource()
        {
            _instance = new ControlInfoDataSource();
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Instance
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 생성자 - ControlInfoDataSource()

        /// <summary>
        /// 생성자
        /// </summary>
        private ControlInfoDataSource()
        {
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 데이터 그룹 열거 가능형 구하기 (비동기) - GetDataGroupEnumerableAsync()

        /// <summary>
        /// 데이터 그룹 열거 가능형 구하기 (비동기)
        /// </summary>
        /// <returns>데이터 그룹 열거 가능형</returns>
        public async Task<IEnumerable<ControlInfoDataGroup>> GetDataGroupEnumerableAsync()
        {
            await _instance.GetControlInfoDataAsync();

            return _instance.DataGroupList;
        }

        #endregion
        #region 데이터 그룹 구하기 (비동기) - GetDataGroupAsync(uniqueID)

        /// <summary>
        /// 데이터 그룹 구하기 (비동기)
        /// </summary>
        /// <param name="uniqueID">고유 ID</param>
        /// <returns>데이터 그룹 태스크</returns>
        public async Task<ControlInfoDataGroup> GetDataGroupAsync(string uniqueID)
        {
            await _instance.GetControlInfoDataAsync();

            IEnumerable<ControlInfoDataGroup> dataGroupEnumerable = _instance.DataGroupList.Where((group) => group.UniqueID.Equals(uniqueID));

            if(dataGroupEnumerable.Count() == 1)
            {
                return dataGroupEnumerable.First();
            }

            return null;
        }

        #endregion
        #region 데이터 항목 구하기 (비동기) - GetDataItemAsync(uniqueID)

        /// <summary>
        /// 데이터 항목 구하기 (비동기)
        /// </summary>
        /// <param name="uniqueID">고유 ID</param>
        /// <returns>데이터 항목 태스크</returns>
        public async Task<ControlInfoDataItem> GetDataItemAsync(string uniqueID)
        {
            await _instance.GetControlInfoDataAsync();

            IEnumerable<ControlInfoDataItem> dataItemEnumerable = _instance.DataGroupList.SelectMany(group => group.DataItemCollection)
                                                                                         .Where((item) => item.UniqueID.Equals(uniqueID));

            if(dataItemEnumerable.Count() > 0)
            {
                return dataItemEnumerable.First();
            }

            return null;
        }

        #endregion
        #region 항목에서 데이터 그룹 구하기 (비동기) - GetDataGroupFromItemAsync(uniqueID)

        /// <summary>
        /// 항목에서 데이터 그룹 구하기 (비동기)
        /// </summary>
        /// <param name="uniqueID">고유 ID</param>
        /// <returns>데이터 그룹 태스크</returns>
        public async Task<ControlInfoDataGroup> GetDataGroupFromItemAsync(string uniqueID)
        {
            await _instance.GetControlInfoDataAsync();

            IEnumerable<ControlInfoDataGroup> dataGroupEnumerable = _instance.DataGroupList.Where
            (
                (group) => group.DataItemCollection.FirstOrDefault(item => item.UniqueID.Equals(uniqueID)) != null
            );

            if(dataGroupEnumerable.Count() == 1)
            {
                return dataGroupEnumerable.First();
            }

            return null;
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 컨트롤 정보 데이터 구하기 - GetControlInfoDataAsync()

        /// <summary>
        /// 컨트롤 정보 데이터 구하기
        /// </summary>
        /// <returns>태스크</returns>
        private async Task GetControlInfoDataAsync()
        {
            lock(_lockObject)
            {
                if(DataGroupList.Count() != 0)
                {
                    return;
                }
            }

            Uri dataURI = new Uri("ms-appx:///DATA/ControlInfoData.json");

            StorageFile storageFile = await StorageFile.GetFileFromApplicationUriAsync(dataURI);

            string json = await FileIO.ReadTextAsync(storageFile);

            JsonObject jsonObject = JsonObject.Parse(json);
            JsonArray  jsonArray  = jsonObject["Groups"].GetArray();

            lock(_lockObject)
            {
                foreach(JsonValue groupValue in jsonArray)
                {
                    JsonObject groupObject = groupValue.GetObject();

                    ControlInfoDataGroup group = new ControlInfoDataGroup
                    (
                        groupObject["UniqueId"   ].GetString(),
                        groupObject["Title"      ].GetString(),
                        groupObject["Subtitle"   ].GetString(),
                        groupObject["ImagePath"  ].GetString(),
                        groupObject["Description"].GetString()
                    );

                    foreach(JsonValue itemValue in groupObject["Items"].GetArray())
                    {
                        JsonObject itemObject = itemValue.GetObject();

                        string badgeString = null;

                        bool isNew     = itemObject.ContainsKey("IsNew"    ) ? itemObject["IsNew"    ].GetBoolean() : false;
                        bool isUpdated = itemObject.ContainsKey("IsUpdated") ? itemObject["IsUpdated"].GetBoolean() : false;
                        bool isPreview = itemObject.ContainsKey("IsPreview") ? itemObject["IsPreview"].GetBoolean() : false;

                        if(isNew)
                        {
                            badgeString = "New";
                        }
                        else if(isUpdated)
                        {
                            badgeString = "Updated";
                        }
                        else if(isPreview)
                        {
                            badgeString = "Preview";
                        }

                        ControlInfoDataItem item = new ControlInfoDataItem
                        (
                            itemObject["UniqueId"   ].GetString(),
                            itemObject["Title"      ].GetString(),
                            itemObject["Subtitle"   ].GetString(),
                            itemObject["ImagePath"  ].GetString(),
                            badgeString,
                            itemObject["Description"].GetString(),
                            itemObject["Content"    ].GetString(),
                            isNew,
                            isUpdated,
                            isPreview
                        );

                        if(itemObject.ContainsKey("Docs"))
                        {
                            foreach(JsonValue documentValue in itemObject["Docs"].GetArray())
                            {
                                JsonObject documentObject = documentValue.GetObject();

                                item.DocumentLinkCollection.Add
                                (
                                    new ControlInfoDocumentLink
                                    (
                                        documentObject["Title"].GetString(),
                                        documentObject["Uri"  ].GetString()
                                    )
                                );
                            }
                        }

                        if(itemObject.ContainsKey("RelatedControls"))
                        {
                            foreach(JsonValue relatedControlValue in itemObject["RelatedControls"].GetArray())
                            {
                                item.RelatedControlCollection.Add(relatedControlValue.GetString());
                            }
                        }

                        group.DataItemCollection.Add(item);
                    }

                    if(!DataGroupList.Any(g => g.Title == group.Title))
                    {
                        DataGroupList.Add(group);
                    }
                }
            }
        }

        #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"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Grid
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <AutoSuggestBox Grid.Row="0"
                Width="300"
                QueryIcon="Find"
                PlaceholderText="컨트롤명을 입력해 주시기 바랍니다."
                TextChanged="autoSuggestBox_TextChanged"
                QuerySubmitted="autoSuggestBox_QuerySubmitted"
                SuggestionChosen="autoSuggestBox_SuggestionChosen" />
            <RelativePanel Name="relativePanel" Grid.Row="1"
                HorizontalAlignment="Left"
                Margin="0 10 0 0"
                Visibility="Collapsed">
                <Image Name="image"
                    Width="48"
                    Height="47" />
                <TextBlock Name="titleTextBlock"
                    Style="{StaticResource BaseTextBlockStyle}"
                    RelativePanel.RightOf="image"
                    Margin="10 0 0 0" />
                <TextBlock Name="subtitleTextBlock"
                    RelativePanel.Below="titleTextBlock"
                    RelativePanel.AlignLeftWith="titleTextBlock"
                    Margin="10 0 0 0"
                    TextWrapping="WrapWholeWords" />
            </RelativePanel>
        </Grid>
    </Grid>
</Page>

 

▶ MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;

namespace TestProject
{
    /// <summary>
    /// 메인 페이지
    /// </summary>
    public sealed partial class MainPage : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// 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 = "AutoSuggestBox 엘리먼트 : QuerySubmitted 이벤트 사용하기";

            #endregion
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 자동 제안 박스 텍스트 변경시 처리하기 - autoSuggestBox_TextChanged(autoSuggestBox, e)

        /// <summary>
        /// 자동 제안 박스 텍스트 변경시 처리하기
        /// </summary>
        /// <param name="autoSuggestBox">자동 제안 박스</param>
        /// <param name="e">이벤트 인자</param>
        private void autoSuggestBox_TextChanged(AutoSuggestBox autoSuggestBox, AutoSuggestBoxTextChangedEventArgs e)
        {
            if(e.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                List<ControlInfoDataItem> resultList = GetControlInfoDataItemList(autoSuggestBox.Text);

                if(resultList.Count > 0)
                {
                    autoSuggestBox.ItemsSource = resultList;
                }
                else
                {
                    autoSuggestBox.ItemsSource = new string[] { "검색 결과가 없습니다." };
                }
            }
        }

        #endregion
        #region 자동 제안 박스 질의 제출시 처리하기 - autoSuggestBox_QuerySubmitted(autoSuggestBox, e)

        /// <summary>
        /// 자동 제안 박스 질의 제출시 처리하기
        /// </summary>
        /// <param name="autoSuggestBox">자동 제안 박스</param>
        /// <param name="e">이벤트 인자</param>
        private void autoSuggestBox_QuerySubmitted(AutoSuggestBox autoSuggestBox, AutoSuggestBoxQuerySubmittedEventArgs e)
        {
            if(e.ChosenSuggestion != null && e.ChosenSuggestion is ControlInfoDataItem)
            {
                SetControlData(e.ChosenSuggestion as ControlInfoDataItem);
            }
            else if(!string.IsNullOrEmpty(e.QueryText))
            {
                List<ControlInfoDataItem> resultList = GetControlInfoDataItemList(autoSuggestBox.Text);

                if(resultList.Count > 0)
                {
                    SetControlData(resultList.FirstOrDefault());
                }
            }
        }

        #endregion
        #region 자동 제안 박스 제안 선택시 처리하기 - autoSuggestBox_SuggestionChosen(autoSuggestBox, e)

        /// <summary>
        /// 자동 제안 박스 제안 선택시 처리하기
        /// </summary>
        /// <param name="autoSuggestBox">자동 제안 박스</param>
        /// <param name="e">이벤트 인자</param>
        private void autoSuggestBox_SuggestionChosen(AutoSuggestBox autoSuggestBox, AutoSuggestBoxSuggestionChosenEventArgs e)
        {
            if(e.SelectedItem is ControlInfoDataItem item)
            {
                autoSuggestBox.Text = item.Title;
            }
        }

        #endregion

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

        #region 컨트롤 정보 데이터 항목 리스트 구하기 - GetControlInfoDataItemList(query)

        /// <summary>
        /// 컨트롤 정보 데이터 항목 리스트 구하기
        /// </summary>
        /// <param name="query">쿼리</param>
        /// <returns>컨트롤 정보 데이터 항목 리스트</returns>
        private List<ControlInfoDataItem> GetControlInfoDataItemList(string query)
        {
            List<ControlInfoDataItem> list = new List<ControlInfoDataItem>();

            string[] tokenArray = query.Split(" ");

            foreach(ControlInfoDataGroup group in ControlInfoDataSource.Instance.DataGroupList)
            {
                IEnumerable<ControlInfoDataItem> itemEnumerable = group.DataItemCollection.Where
                (
                    item =>
                    {
                        bool flag = true;

                        foreach(string token in tokenArray)
                        {
                            if(item.Title.IndexOf(token, StringComparison.CurrentCultureIgnoreCase) < 0)
                            {
                                flag = false;
                            }
                        }

                        return flag;
                    }
                );

                foreach(ControlInfoDataItem item in itemEnumerable)
                {
                    list.Add(item);
                }
            }

            return list.OrderByDescending
            (
                i => i.Title.StartsWith(query, StringComparison.CurrentCultureIgnoreCase)
            )
            .ThenBy(i => i.Title)
            .ToList();
        }

        #endregion
        #region 컨트롤 데이터 설정하기 - SetControlData(item)

        /// <summary>
        /// 컨트롤 데이터 설정하기
        /// </summary>
        /// <param name="item">컨트롤 정보 데이터 항목</param>
        private void SetControlData(ControlInfoDataItem item)
        {
            if(item != null)
            {
                this.relativePanel.Visibility = Visibility.Visible;

                BitmapImage bitmapImage = new BitmapImage(new Uri(item.ImagePath));

                this.image.Source = bitmapImage;

                this.titleTextBlock.Text    = item.Title;
                this.subtitleTextBlock.Text = item.Subtitle;
            }
        }

        #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">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources> 
</Application>

 

▶ App.xaml.cs

using System;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
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 async override void OnLaunched(LaunchActivatedEventArgs e)
        {
            await ControlInfoDataSource.Instance.GetDataGroupEnumerableAsync();

            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();
            }
        }

        #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
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker
TAG , , ,

댓글을 달아 주세요