{"id":37551,"date":"2024-11-01T09:58:28","date_gmt":"2024-11-01T09:58:28","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37551"},"modified":"2024-11-01T11:02:16","modified_gmt":"2024-11-01T11:02:16","slug":"uwp-development-key-events-of-uwp-app","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37551\/","title":{"rendered":"UWP Development, Key Events of UWP App"},"content":{"rendered":"<p>UWP (Universal Windows Platform) development is a powerful platform that allows developers to create applications that run on Windows 10 and later versions. UWP applications are designed to run on a variety of devices and provide a user interface that can be used across desktops, tablets, Xbox, IoT devices, and more. In this article, we will explain the important &#8216;events&#8217; in UWP app development in detail and illustrate them with actual code examples.<\/p>\n<h2>1. What are events?<\/h2>\n<p>Events refer to methods that are called when a specific action or state change occurs. In UWP applications, events are used to handle various occurrences such as user input, system changes, and application state changes. Developers can register handlers for these events to execute appropriate responses when an event occurs.<\/p>\n<h2>2. Key types of events in UWP<\/h2>\n<p>The commonly used types of events in UWP development are as follows:<\/p>\n<ul>\n<li><strong>UI events:<\/strong> Events related to user input (clicks, touches, etc.) that occur on UI elements.<\/li>\n<li><strong>Data events:<\/strong> Events related to changes in data that occur in the data model.<\/li>\n<li><strong>Application events:<\/strong> Events related to the overall state changes of the application that occur during the app&#8217;s lifecycle.<\/li>\n<\/ul>\n<h2>3. Handling UI events<\/h2>\n<p>In UWP, UI events are most frequently used to handle interactions with users. The core of event-driven programming is to detect and handle events. Below is an example of handling a button click event.<\/p>\n<h3>3.1 Example of button click event handling<\/h3>\n<pre><code class=\"language-csharp\">\nusing Windows.UI.Xaml;\nusing Windows.UI.Xaml.Controls;\n\nnamespace UWPAppExample\n{\n    public sealed partial class MainPage : Page\n    {\n        public MainPage()\n        {\n            this.InitializeComponent();\n        }\n\n        private void MyButton_Click(object sender, RoutedEventArgs e)\n        {\n            MyTextBlock.Text = \"The button has been clicked!\";\n        }\n    }\n}\n<\/code><\/pre>\n<p>In the above code, the <code>MyButton_Click<\/code> method is called when <code>MyButton<\/code> is clicked. To connect the UI element and the event handler, the following settings are needed in the XAML file.<\/p>\n<pre><code class=\"language-xml\">\n<button click=\"MyButton_Click\" content=\"Click me!\" x:name=\"MyButton\"><\/button>\n<textblock text=\"\" x:name=\"MyTextBlock\"><\/textblock>\n<\/code><\/pre>\n<h2>4. Handling data events<\/h2>\n<p>Data events occur in response to changes in data. These events are utilized in UWP applications that use data binding when the state of the data model changes.<\/p>\n<h3>4.1 Data change events using ObservableCollection<\/h3>\n<pre><code class=\"language-csharp\">\nusing System.Collections.ObjectModel;\nusing Windows.UI.Xaml.Controls;\n\nnamespace UWPAppExample\n{\n    public sealed partial class MainPage : Page\n    {\n        public ObservableCollection<string> Items { get; set; }\n\n        public MainPage()\n        {\n            this.InitializeComponent();\n            Items = new ObservableCollection<string>();\n            MyListView.ItemsSource = Items;\n            Items.CollectionChanged += Items_CollectionChanged;\n        }\n\n        private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)\n        {\n            if (e.NewItems != null)\n            {\n                foreach (var newItem in e.NewItems)\n                {\n                    \/\/ Process when a new item is added\n                }\n            }\n        }\n\n        private void AddButton_Click(object sender, RoutedEventArgs e)\n        {\n            Items.Add(\"New item\");\n        }\n    }\n}\n<\/code><\/pre>\n<p>The above code uses <code>ObservableCollection<\/code> to handle data binding. When a new item is added to the collection, the <code>Items_CollectionChanged<\/code> method is called. This method can process additional actions in response to data changes.<\/p>\n<h2>5. Handling application events<\/h2>\n<p>Application events occur during the application lifecycle. For example, events that occur when the application starts or ends fall into this category.<\/p>\n<h3>5.1 Managing app lifecycle<\/h3>\n<pre><code class=\"language-csharp\">\nusing Windows.UI.Xaml;\n\nnamespace UWPAppExample\n{\n    public sealed partial class App : Application\n    {\n        public App()\n        {\n            this.InitializeComponent();\n            this.Suspending += OnSuspending;\n            this.Launched += OnLaunched;\n        }\n\n        private void OnLaunched(object sender, LaunchActivatedEventArgs e)\n        {\n            Frame rootFrame = Window.Current.Content as Frame;\n\n            if (rootFrame == null)\n            {\n                rootFrame = new Frame();\n                Window.Current.Content = rootFrame;\n            }\n\n            if (rootFrame.Content == null)\n            {\n                rootFrame.Navigate(typeof(MainPage), e.Arguments);\n            }\n\n            Window.Current.Activate();\n        }\n\n        private void OnSuspending(object sender, SuspendingEventArgs e)\n        {\n            \/\/ Logic to handle when the application is suspended\n        }\n    }\n}\n<\/code><\/pre>\n<p>The above code handles events that occur when the application starts and stops. The <code>OnLaunched<\/code> method is called when the application is launched to perform initialization tasks, while the <code>OnSuspending<\/code> method handles necessary tasks when the application is suspended.<\/p>\n<h2>6. Considerations when handling events<\/h2>\n<ul>\n<li>Event handler methods should be written as concisely as possible, and complex logic should be separated into additional methods.<\/li>\n<li>To prevent performance degradation when events occur, unnecessary work should be minimized.<\/li>\n<li>Be careful not to register or unregister events multiple times, as this can lead to memory leaks.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In UWP application development, events are a core element of managing user interfaces (UI), data, and application state. This article examined the main types of events in UWP apps and how to handle them with example code. By utilizing event-driven programming, you can handle interactions with users more smoothly, respond immediately to data changes, and efficiently manage the application&#8217;s lifecycle.<\/p>\n<p>As you continue to practice and develop with UWP, I hope you create more creative and diverse applications with various features.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UWP (Universal Windows Platform) development is a powerful platform that allows developers to create applications that run on Windows 10 and later versions. UWP applications are designed to run on a variety of devices and provide a user interface that can be used across desktops, tablets, Xbox, IoT devices, and more. In this article, we &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37551\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;UWP Development, Key Events of UWP App&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[115],"tags":[],"class_list":["post-37551","post","type-post","status-publish","format-standard","hentry","category-uwp-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>UWP Development, Key Events of UWP App - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/37551\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UWP Development, Key Events of UWP App - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"UWP (Universal Windows Platform) development is a powerful platform that allows developers to create applications that run on Windows 10 and later versions. UWP applications are designed to run on a variety of devices and provide a user interface that can be used across desktops, tablets, Xbox, IoT devices, and more. In this article, we &hellip; \ub354 \ubcf4\uae30 &quot;UWP Development, Key Events of UWP App&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37551\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:58:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:02:16+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37551\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37551\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"UWP Development, Key Events of UWP App\",\"datePublished\":\"2024-11-01T09:58:28+00:00\",\"dateModified\":\"2024-11-01T11:02:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37551\/\"},\"wordCount\":538,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"UWP Programming\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37551\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37551\/\",\"name\":\"UWP Development, Key Events of UWP App - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:58:28+00:00\",\"dateModified\":\"2024-11-01T11:02:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37551\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37551\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37551\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UWP Development, Key Events of UWP App\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UWP Development, Key Events of UWP App - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/37551\/","og_locale":"ko_KR","og_type":"article","og_title":"UWP Development, Key Events of UWP App - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"UWP (Universal Windows Platform) development is a powerful platform that allows developers to create applications that run on Windows 10 and later versions. UWP applications are designed to run on a variety of devices and provide a user interface that can be used across desktops, tablets, Xbox, IoT devices, and more. In this article, we &hellip; \ub354 \ubcf4\uae30 \"UWP Development, Key Events of UWP App\"","og_url":"https:\/\/atmokpo.com\/w\/37551\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:58:28+00:00","article_modified_time":"2024-11-01T11:02:16+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37551\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37551\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"UWP Development, Key Events of UWP App","datePublished":"2024-11-01T09:58:28+00:00","dateModified":"2024-11-01T11:02:16+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37551\/"},"wordCount":538,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["UWP Programming"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37551\/","url":"https:\/\/atmokpo.com\/w\/37551\/","name":"UWP Development, Key Events of UWP App - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:58:28+00:00","dateModified":"2024-11-01T11:02:16+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37551\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37551\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37551\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"UWP Development, Key Events of UWP App"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=37551"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37551\/revisions"}],"predecessor-version":[{"id":37552,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37551\/revisions\/37552"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}