■ AutoSuggestBox 엘리먼트의 QuerySubmitted 이벤트를 사용하는 방법을 보여준다.
▶ ControlInfoDocumentLink.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 |
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 } } |
▶ ControlInfoDataItem.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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
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 } } |
▶ ControlInfoDataGroup.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 |
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
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
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
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 |
<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
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<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
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 |
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 } } |