{"id":37621,"date":"2024-11-01T09:59:03","date_gmt":"2024-11-01T09:59:03","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37621"},"modified":"2024-11-01T11:01:59","modified_gmt":"2024-11-01T11:01:59","slug":"uwp-development-custom-resource","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37621\/","title":{"rendered":"UWP Development, Custom Resource"},"content":{"rendered":"<p>Windows Universal Platform (UWP) development focuses on creating apps that run on various Windows 10 devices. One important aspect of UWP app development is creating reusable resources. Custom Resources help maintain consistency in the app, enhance code reusability, and facilitate easier maintenance later. In this article, we will explore how to create and utilize custom resources in UWP.<\/p>\n<h2>1. What is a Resource?<\/h2>\n<p>In UWP and XAML-based applications, a &#8216;resource&#8217; is a collection of data used to define and style various components of the application. Resources can include colors, brushes, styles, templates, etc., and by defining these resources, developers can increase code efficiency and reuse common elements.<\/p>\n<h2>2. The Importance of Custom Resources<\/h2>\n<p>Custom resources are important for the following reasons:<\/p>\n<ul>\n<li><strong>Consistency:<\/strong> Styles can be easily applied to ensure that the app&#8217;s UI elements look consistent.<\/li>\n<li><strong>Reusability:<\/strong> By reusing the same resource in multiple places, code duplication can be reduced.<\/li>\n<li><strong>Maintenance:<\/strong> If a resource changes, the changes will automatically be reflected in all elements that use that resource.<\/li>\n<\/ul>\n<h2>3. Creating Custom Resources<\/h2>\n<h3>3.1. Creating a Resource Dictionary<\/h3>\n<p>First, you need to create a Resource Dictionary where you will define your custom resources. To do this, create a XAML file and add code to define the resources.<\/p>\n<pre><code>&lt;ResourceDictionary xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\" \n    xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"&gt;\n\n    &lt;Color x:Key=\"PrimaryColor\"&gt;#FF6200EE&lt;\/Color&gt;\n    &lt;SolidColorBrush x:Key=\"PrimaryBrush\" Color=\"{StaticResource PrimaryColor}\" \/&gt;\n\n    &lt;Style TargetType=\"Button\" x:Key=\"PrimaryButtonStyle\"&gt;\n        &lt;Setter Property=\"Background\" Value=\"{StaticResource PrimaryBrush}\" \/&gt;\n        &lt;Setter Property=\"Foreground\" Value=\"White\" \/&gt;\n        &lt;Setter Property=\"Padding\" Value=\"10\" \/&gt;\n    &lt;\/Style&gt;\n\n&lt;\/ResourceDictionary&gt;<\/code><\/pre>\n<p>In the example above, we defined a Resource Dictionary that includes a primary color and button style. This Dictionary can be reused across various parts of the app.<\/p>\n<h3>3.2. Using the Resource Dictionary<\/h3>\n<p>Once you&#8217;ve defined your resources, you can use them within your UWP app. First, here is how to reference the resource Dictionary in the App.xaml file:<\/p>\n<pre><code>&lt;Application.Resources&gt;\n    &lt;ResourceDictionary&gt;\n        &lt;ResourceDictionary.MergedDictionaries&gt;\n            &lt;ResourceDictionary Source=\"Assets\/YourResourceDictionary.xaml\" \/&gt;\n        &lt;\/ResourceDictionary.MergedDictionaries&gt;\n    &lt;\/ResourceDictionary&gt;\n&lt;\/Application.Resources&gt;<\/code><\/pre>\n<p>Here, &#8216;YourResourceDictionary.xaml&#8217; is the filename of the resource dictionary you created. This will allow resources to be accessed globally throughout the app.<\/p>\n<h3>3.3. Example of Using a Resource<\/h3>\n<p>Here\u2019s how to use the defined resource in a real UWP app:<\/p>\n<pre><code>&lt;Button Content=\"Click Me!\" Style=\"{StaticResource PrimaryButtonStyle}\" \/&gt;<\/code><\/pre>\n<p>This code applies the custom &#8216;PrimaryButtonStyle&#8217; to the button, ensuring consistent styling.<\/p>\n<h2>4. Dynamic Resources<\/h2>\n<p>UWP also supports a feature called &#8216;Dynamic Resources&#8217; that allows resources to be changed dynamically. Using dynamic resources, you can change resources while the application is running, and the changes are immediately reflected in the UI. Dynamic resources can be declared as follows:<\/p>\n<pre><code>&lt;Button Content=\"Change Color\" Background=\"{DynamicResource PrimaryBrush}\" Click=\"OnChangeColorButtonClick\" \/&gt;<\/code><\/pre>\n<p>Let\u2019s look at an example where clicking the above button changes the background color of the button:<\/p>\n<pre><code>private void OnChangeColorButtonClick(object sender, RoutedEventArgs e)\n{\n    \/\/ Change the existing resource to a new color\n    Application.Current.Resources[\"PrimaryBrush\"] = new SolidColorBrush(Colors.Red);\n}<\/code><\/pre>\n<h2>5. Conclusion<\/h2>\n<p>Utilizing custom resources can enhance productivity in UWP app development and maintain consistency in the UI. With what you&#8217;ve learned today, you should be able to easily implement and utilize custom resources in your apps. By defining and experimenting with various resources, you can add unique styles and flexibility to your apps.<\/p>\n<p>To gain a deeper understanding of UWP development, it is recommended to refer to the official Microsoft documentation and related educational materials. In future courses, we will cover more possibilities of UWP, so we appreciate your interest!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows Universal Platform (UWP) development focuses on creating apps that run on various Windows 10 devices. One important aspect of UWP app development is creating reusable resources. Custom Resources help maintain consistency in the app, enhance code reusability, and facilitate easier maintenance later. In this article, we will explore how to create and utilize custom &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37621\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;UWP Development, Custom Resource&#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-37621","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, Custom Resource - \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\/37621\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UWP Development, Custom Resource - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Windows Universal Platform (UWP) development focuses on creating apps that run on various Windows 10 devices. One important aspect of UWP app development is creating reusable resources. Custom Resources help maintain consistency in the app, enhance code reusability, and facilitate easier maintenance later. In this article, we will explore how to create and utilize custom &hellip; \ub354 \ubcf4\uae30 &quot;UWP Development, Custom Resource&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37621\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:59:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:01:59+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=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/37621\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37621\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"UWP Development, Custom Resource\",\"datePublished\":\"2024-11-01T09:59:03+00:00\",\"dateModified\":\"2024-11-01T11:01:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37621\/\"},\"wordCount\":473,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"UWP Programming\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37621\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37621\/\",\"name\":\"UWP Development, Custom Resource - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:59:03+00:00\",\"dateModified\":\"2024-11-01T11:01:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37621\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37621\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37621\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UWP Development, Custom Resource\"}]},{\"@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, Custom Resource - \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\/37621\/","og_locale":"ko_KR","og_type":"article","og_title":"UWP Development, Custom Resource - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Windows Universal Platform (UWP) development focuses on creating apps that run on various Windows 10 devices. One important aspect of UWP app development is creating reusable resources. Custom Resources help maintain consistency in the app, enhance code reusability, and facilitate easier maintenance later. In this article, we will explore how to create and utilize custom &hellip; \ub354 \ubcf4\uae30 \"UWP Development, Custom Resource\"","og_url":"https:\/\/atmokpo.com\/w\/37621\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:59:03+00:00","article_modified_time":"2024-11-01T11:01:59+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":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/37621\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37621\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"UWP Development, Custom Resource","datePublished":"2024-11-01T09:59:03+00:00","dateModified":"2024-11-01T11:01:59+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37621\/"},"wordCount":473,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["UWP Programming"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37621\/","url":"https:\/\/atmokpo.com\/w\/37621\/","name":"UWP Development, Custom Resource - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:59:03+00:00","dateModified":"2024-11-01T11:01:59+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37621\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37621\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37621\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"UWP Development, Custom Resource"}]},{"@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\/37621","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=37621"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37621\/revisions"}],"predecessor-version":[{"id":37622,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37621\/revisions\/37622"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}