{"id":37623,"date":"2024-11-01T09:59:04","date_gmt":"2024-11-01T09:59:04","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37623"},"modified":"2024-11-01T11:01:58","modified_gmt":"2024-11-01T11:01:58","slug":"uwp-development-property-elements-and-attached-properties","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37623\/","title":{"rendered":"UWP Development, Property Elements and Attached Properties"},"content":{"rendered":"<p>Hello! In this tutorial, we will take a closer look at two important concepts in Windows UWP (Universal Windows Platform) development: Dependency Properties and Attached Properties. UWP is a powerful platform that supports the development of applications that can run on a variety of devices. Dependency Properties and Attached Properties play a crucial role in setting and controlling the properties of UI elements within this platform.<\/p>\n<h2>1. What are Dependency Properties?<\/h2>\n<p>Dependency Properties are a concept introduced in WPF (Windows Presentation Foundation) that is also adopted in UWP. Dependency Properties have the following characteristics:<\/p>\n<ul>\n<li>They can define the properties of UI elements.<\/li>\n<li>They can track changes to property values and update the UI based on those changes.<\/li>\n<li>They support data binding and styling features.<\/li>\n<\/ul>\n<h3>1.1 Structure of Dependency Properties<\/h3>\n<p>To define a Dependency Property, you need to create a class that inherits from the <code>DependencyObject<\/code> class and register the necessary Dependency Properties. For this, you will use the <code>DependencyProperty.Register<\/code> method.<\/p>\n<h4>Example: Defining a Custom Dependency Property<\/h4>\n<pre><code class=\"language-csharp\">using Windows.UI.Xaml;\n\npublic class MyCustomControl : Control\n{\n    \/\/ Defining Dependency Property\n    public static readonly DependencyProperty MyPropertyProperty =\n        DependencyProperty.Register(\n            \"MyProperty\",\n            typeof(string),\n            typeof(MyCustomControl),\n            new PropertyMetadata(default(string)));\n\n    \/\/ CLR Property Wrapper\n    public string MyProperty\n    {\n        get { return (string)GetValue(MyPropertyProperty); }\n        set { SetValue(MyPropertyProperty, value); }\n    }\n}\n<\/code><\/pre>\n<p>The code above defines a custom control named <code>MyCustomControl<\/code> and registers a Dependency Property called <code>MyProperty<\/code>.<\/p>\n<h3>1.2 Characteristics of Dependency Properties<\/h3>\n<p>Dependency Properties have various characteristics. By default, here are some of them:<\/p>\n<ul>\n<li><strong>Default Value<\/strong>: You can set the default value of a property.<\/li>\n<li><strong>Change Notification<\/strong>: You can receive notifications when the property value changes.<\/li>\n<li><strong>Data Binding<\/strong>: You can bind properties to a data context.<\/li>\n<\/ul>\n<h2>2. What are Attached Properties?<\/h2>\n<p>Attached Properties are properties used to provide additional properties to specific objects. These properties are typically used in other classes and are very useful in design scenarios. They are useful for providing directional information (e.g., layout information regarding specific UI elements).<\/p>\n<h3>2.1 Structure of Attached Properties<\/h3>\n<p>The method of defining Attached Properties is similar to that of defining Dependency Properties. They can be defined accordingly.<\/p>\n<h4>Example: Defining an Attached Property<\/h4>\n<pre><code class=\"language-csharp\">public static class MyAttachedProperties\n{\n    public static readonly DependencyProperty IsMyPropertyProperty =\n        DependencyProperty.RegisterAttached(\n            \"IsMyProperty\",\n            typeof(bool),\n            typeof(MyAttachedProperties),\n            new PropertyMetadata(false));\n\n    public static void SetIsMyProperty(UIElement element, bool value)\n    {\n        element.SetValue(IsMyPropertyProperty, value);\n    }\n\n    public static bool GetIsMyProperty(UIElement element)\n    {\n        return (bool)element.GetValue(IsMyPropertyProperty);\n    }\n}\n<\/code><\/pre>\n<p>The code above defines an Attached Property named <code>IsMyProperty<\/code> in the <code>MyAttachedProperties<\/code> class. Attached Properties can be applied to UI elements of other classes from outside the class.<\/p>\n<h3>2.2 Use of Attached Properties<\/h3>\n<p>Attached Properties are primarily useful in the following situations:<\/p>\n<ul>\n<li>A parent element can pass data to child elements.<\/li>\n<li>You can dynamically add properties to a specific UI element as needed.<\/li>\n<li>They are useful for layout and style adjustments.<\/li>\n<\/ul>\n<h2>3. Comparison of Dependency Properties and Attached Properties<\/h2>\n<p>Dependency Properties are properties defined within a class, while Attached Properties are properties that can be set externally on specific UI elements. Dependency Properties can be directly used in instances of the class, whereas Attached Properties are primarily used as additional properties for UI elements.<\/p>\n<h2>4. Examples of Dependency Properties and Attached Properties<\/h2>\n<p>Below is a simple example of using both Dependency Properties and Attached Properties together.<\/p>\n<h4>Example: Combining Custom Control with Attached Properties<\/h4>\n<pre><code class=\"language-csharp\">public class MyCustomControl : Control\n{\n    \/\/ Defining Dependency Property\n    public static readonly DependencyProperty MyPropertyProperty =\n        DependencyProperty.Register(\n            \"MyProperty\",\n            typeof(string),\n            typeof(MyCustomControl),\n            new PropertyMetadata(default(string)));\n\n    public string MyProperty\n    {\n        get { return (string)GetValue(MyPropertyProperty); }\n        set { SetValue(MyPropertyProperty, value); }\n    }\n}\n\npublic static class MyAttachedProperties\n{\n    public static readonly DependencyProperty IsMyPropertyProperty =\n        DependencyProperty.RegisterAttached(\n            \"IsMyProperty\",\n            typeof(bool),\n            typeof(MyAttachedProperties),\n            new PropertyMetadata(false));\n\n    public static void SetIsMyProperty(UIElement element, bool value)\n    {\n        element.SetValue(IsMyPropertyProperty, value);\n    }\n\n    public static bool GetIsMyProperty(UIElement element)\n    {\n        return (bool)element.GetValue(IsMyPropertyProperty);\n    }\n}\n<\/code><\/pre>\n<h2>5. Practical Example: Building a Simple UWP App<\/h2>\n<p>Now, let&#8217;s apply the above Dependency Properties and Attached Properties to a simple UWP application.<\/p>\n<h3>5.1 Writing the XAML File<\/h3>\n<pre><code class=\"language-xaml\">&lt;Page\n    x:Class=\"MyApp.MainPage\"\n    xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n    xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n    xmlns:local=\"using:MyApp\"\n    xmlns:controls=\"using:MyApp.Controls\"&gt;\n\n    &lt;Grid&gt;\n        &lt;controls:MyCustomControl MyProperty=\"Hello, World!\" \n            local:MyAttachedProperties.IsMyProperty=\"True\" \/&gt;\n    &lt;\/Grid&gt;\n&lt;\/Page&gt;<\/code><\/pre>\n<h3>5.2 Writing the C# Code<\/h3>\n<pre><code class=\"language-csharp\">using Windows.UI.Xaml.Controls;\n\nnamespace MyApp\n{\n    public sealed partial class MainPage : Page\n    {\n        public MainPage()\n        {\n            this.InitializeComponent();\n        }\n    }\n}<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we explored the concepts of Dependency Properties and Attached Properties in UWP development. Dependency Properties manage the properties of custom controls, while Attached Properties are used to dynamically add additional properties to UI elements. Properly leveraging these two concepts can greatly assist in developing large-scale applications.<\/p>\n<p>Now you have the foundation to enrich your UWP applications using Dependency Properties and Attached Properties. Furthermore, apply these concepts to create applications with various features!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this tutorial, we will take a closer look at two important concepts in Windows UWP (Universal Windows Platform) development: Dependency Properties and Attached Properties. UWP is a powerful platform that supports the development of applications that can run on a variety of devices. Dependency Properties and Attached Properties play a crucial role in &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37623\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;UWP Development, Property Elements and Attached Properties&#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-37623","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, Property Elements and Attached Properties - \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\/37623\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UWP Development, Property Elements and Attached Properties - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this tutorial, we will take a closer look at two important concepts in Windows UWP (Universal Windows Platform) development: Dependency Properties and Attached Properties. UWP is a powerful platform that supports the development of applications that can run on a variety of devices. Dependency Properties and Attached Properties play a crucial role in &hellip; \ub354 \ubcf4\uae30 &quot;UWP Development, Property Elements and Attached Properties&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37623\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:59:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:01:58+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\/37623\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37623\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"UWP Development, Property Elements and Attached Properties\",\"datePublished\":\"2024-11-01T09:59:04+00:00\",\"dateModified\":\"2024-11-01T11:01:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37623\/\"},\"wordCount\":560,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"UWP Programming\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37623\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37623\/\",\"name\":\"UWP Development, Property Elements and Attached Properties - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:59:04+00:00\",\"dateModified\":\"2024-11-01T11:01:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37623\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37623\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37623\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UWP Development, Property Elements and Attached Properties\"}]},{\"@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, Property Elements and Attached Properties - \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\/37623\/","og_locale":"ko_KR","og_type":"article","og_title":"UWP Development, Property Elements and Attached Properties - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this tutorial, we will take a closer look at two important concepts in Windows UWP (Universal Windows Platform) development: Dependency Properties and Attached Properties. UWP is a powerful platform that supports the development of applications that can run on a variety of devices. Dependency Properties and Attached Properties play a crucial role in &hellip; \ub354 \ubcf4\uae30 \"UWP Development, Property Elements and Attached Properties\"","og_url":"https:\/\/atmokpo.com\/w\/37623\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:59:04+00:00","article_modified_time":"2024-11-01T11:01:58+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\/37623\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37623\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"UWP Development, Property Elements and Attached Properties","datePublished":"2024-11-01T09:59:04+00:00","dateModified":"2024-11-01T11:01:58+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37623\/"},"wordCount":560,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["UWP Programming"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37623\/","url":"https:\/\/atmokpo.com\/w\/37623\/","name":"UWP Development, Property Elements and Attached Properties - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:59:04+00:00","dateModified":"2024-11-01T11:01:58+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37623\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37623\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37623\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"UWP Development, Property Elements and Attached Properties"}]},{"@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\/37623","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=37623"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37623\/revisions"}],"predecessor-version":[{"id":37624,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37623\/revisions\/37624"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}