{"id":37741,"date":"2024-11-01T10:00:03","date_gmt":"2024-11-01T10:00:03","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37741"},"modified":"2024-11-01T11:03:54","modified_gmt":"2024-11-01T11:03:54","slug":"wpf-development-code-writing-self-written","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37741\/","title":{"rendered":"WPF development, code writing self-written"},"content":{"rendered":"<p>WPF (Windows Presentation Foundation) is a powerful UI framework used to develop Windows applications, as part of the .NET Framework. By leveraging WPF, it becomes easy to build complex user interfaces, offering a rich user experience through features such as data binding, animations, styles, and templates. In this article, we will start with the basics of WPF development and explain how to learn concepts through writing code and how to actually develop applications.<\/p>\n<h2>Basic Concepts of WPF<\/h2>\n<p>WPF uses XAML (eXtensible Application Markup Language) to define the UI and implements business logic using .NET languages like C# or VB.NET. The fundamental elements of WPF are as follows:<\/p>\n<ul>\n<li><strong>XAML (eXtensible Application Markup Language):<\/strong> A markup language used to define WPF UI.<\/li>\n<li><strong>Control:<\/strong> Elements such as Button, TextBox, and ListBox that enable interaction with the user.<\/li>\n<li><strong>Data Binding:<\/strong> Establishes a connection between UI elements and data sources, automatically reflecting changes in the UI.<\/li>\n<li><strong>Styles and Templates:<\/strong> Used to define and customize the appearance of UI elements.<\/li>\n<\/ul>\n<h2>Basics of XAML<\/h2>\n<p>XAML is used to design the UI of WPF applications, and the basic XAML file structure is as follows:<\/p>\n<pre>\n<code>&lt;Window x:Class=\"MyApp.MainWindow\"\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n        Title=\"Main Window\" Height=\"350\" Width=\"525\"&gt;\n    &lt;Grid&gt;\n        &lt;Button Name=\"myButton\" Content=\"Click Me\" Width=\"100\" Height=\"30\" Click=\"myButton_Click\"\/&gt;\n    &lt;\/Grid&gt;\n&lt;\/Window&gt;<\/code>\n<\/pre>\n<h3>Description of UI Elements<\/h3>\n<p>In the above example, <code>&lt;Window&gt;<\/code> defines the main window of the application. <code>&lt;Grid&gt;<\/code> acts as a container for arranging the layout, which includes the <code>&lt;Button&gt;<\/code> element. The <code>Name<\/code> property of the button serves as an identifier for connecting events.<\/p>\n<h2>Writing Logic in C#<\/h2>\n<p>After defining the user interface of a WPF application, actual behaviors must be implemented in C#. Below is a method for handling the button click event.<\/p>\n<pre>\n<code>using System.Windows;\n\nnamespace MyApp\n{\n    public partial class MainWindow : Window\n    {\n        public MainWindow()\n        {\n            InitializeComponent();\n        }\n\n        private void myButton_Click(object sender, RoutedEventArgs e)\n        {\n            MessageBox.Show(\"The button has been clicked!\");\n        }\n    }\n}<\/code>\n<\/pre>\n<h3>Event Handling<\/h3>\n<p>The event handler <code>myButton_Click<\/code> is called when the user clicks the button. It displays a simple message using the <code>MessageBox.Show<\/code> method.<\/p>\n<h2>Understanding Data Binding<\/h2>\n<p>Utilizing data binding in WPF simplifies the connection between the view and the model. Below is an example that uses data binding.<\/p>\n<pre>\n<code>&lt;Window x:Class=\"MyApp.MainWindow\"\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n        Title=\"Data Binding Example\" Height=\"200\" Width=\"400\"&gt;\n    &lt;Grid&gt;\n        &lt;TextBox Text=\"{Binding Name, UpdateSourceTrigger=PropertyChanged}\" Width=\"200\"\/&gt;\n        &lt;TextBlock Text=\"{Binding Name}\" Margin=\"0,30,0,0\"\/&gt;\n    &lt;\/Grid&gt;\n&lt;\/Window&gt;<\/code>\n<\/pre>\n<h3>Data Model Class<\/h3>\n<p>To use data binding, a data model class must first be created. Below is a simple example of a model class.<\/p>\n<pre>\n<code>using System.ComponentModel;\n\nnamespace MyApp\n{\n    public class Person : INotifyPropertyChanged\n    {\n        private string _name;\n\n        public string Name\n        {\n            get { return _name; }\n            set \n            {\n                if (_name != value)\n                {\n                    _name = value;\n                    OnPropertyChanged(\"Name\");\n                }\n            }\n        }\n\n        public event PropertyChangedEventHandler PropertyChanged;\n\n        protected void OnPropertyChanged(string propertyName)\n        {\n            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\n        }\n    }\n}<\/code>\n<\/pre>\n<h2>Understanding ViewModel and MVVM Pattern<\/h2>\n<p>In WPF, the MVVM (Model-View-ViewModel) pattern is used to structure applications. By utilizing the MVVM pattern, you can separate the UI from business logic, enhancing reusability and maintainability. The ViewModel class acts as an intermediary between the view and the model, updating the state of the view through data binding.<\/p>\n<h3>Example of ViewModel Class<\/h3>\n<pre>\n<code>namespace MyApp\n{\n    public class MainViewModel\n    {\n        public Person Person { get; set; }\n\n        public MainViewModel()\n        {\n            Person = new Person { Name = \"John Doe\" };\n        }\n    }\n}<\/code>\n<\/pre>\n<h3>Setting ViewModel Data Context in XAML<\/h3>\n<pre>\n<code>public partial class MainWindow : Window\n{\n    public MainWindow()\n    {\n        InitializeComponent();\n        DataContext = new MainViewModel();\n    }\n}<\/code>\n<\/pre>\n<h2>Utilizing Styles and Templates<\/h2>\n<p>Styles and templates play an essential role in altering the design of WPF UI. Below is an example of applying a style to a button.<\/p>\n<pre>\n<code>&lt;Window.Resources&gt;\n    &lt;Style TargetType=\"Button\"&gt;\n        &lt;Setter Property=\"Background\" Value=\"LightBlue\"\/&gt;\n        &lt;Setter Property=\"Foreground\" Value=\"White\"\/&gt;\n    &lt;\/Style&gt;\n&lt;\/Window.Resources&gt;<\/code>\n<\/pre>\n<h3>Using Templates<\/h3>\n<p>Templates allow you to freely define the layout of UI elements. Below is an example that defines a ControlTemplate for a button.<\/p>\n<pre>\n<code>&lt;Button&gt;\n    &lt;Button.Template&gt;\n        &lt;ControlTemplate TargetType=\"Button\"&gt;\n            &lt;Border Background=\"{TemplateBinding Background}\" BorderBrush=\"Black\" BorderThickness=\"2\"&gt;\n                &lt;ContentPresenter HorizontalAlignment=\"Center\" VerticalAlignment=\"Center\"\/&gt;\n            &lt;\/Border&gt;\n        &lt;\/ControlTemplate&gt;\n    &lt;\/Button.Template&gt;\n    Button Text\n&lt;\/Button&gt;<\/code>\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>In this post, we have explored the basic concepts of WPF development and how to write code. We learned to structure and design applications using XAML and C#, along with data binding, the MVVM pattern, styles, and templates. To develop an actual application, it&#8217;s essential to gradually build upon this foundation by adding more complex functionalities.<\/p>\n<p>WPF is a framework with a broad scope that provides powerful data connectivity and user experience, going beyond simple UI development to create advanced applications. Continue to explore WPF&#8217;s various features and create your own projects!<\/p>\n<p>Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WPF (Windows Presentation Foundation) is a powerful UI framework used to develop Windows applications, as part of the .NET Framework. By leveraging WPF, it becomes easy to build complex user interfaces, offering a rich user experience through features such as data binding, animations, styles, and templates. In this article, we will start with the basics &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37741\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;WPF development, code writing self-written&#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":[117],"tags":[],"class_list":["post-37741","post","type-post","status-publish","format-standard","hentry","category-wpf-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WPF development, code writing self-written - \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\/37741\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WPF development, code writing self-written - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"WPF (Windows Presentation Foundation) is a powerful UI framework used to develop Windows applications, as part of the .NET Framework. By leveraging WPF, it becomes easy to build complex user interfaces, offering a rich user experience through features such as data binding, animations, styles, and templates. In this article, we will start with the basics &hellip; \ub354 \ubcf4\uae30 &quot;WPF development, code writing self-written&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37741\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T10:00:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:03:54+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\/37741\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37741\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"WPF development, code writing self-written\",\"datePublished\":\"2024-11-01T10:00:03+00:00\",\"dateModified\":\"2024-11-01T11:03:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37741\/\"},\"wordCount\":546,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"WPF Programming\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37741\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37741\/\",\"name\":\"WPF development, code writing self-written - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T10:00:03+00:00\",\"dateModified\":\"2024-11-01T11:03:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37741\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37741\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37741\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WPF development, code writing self-written\"}]},{\"@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":"WPF development, code writing self-written - \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\/37741\/","og_locale":"ko_KR","og_type":"article","og_title":"WPF development, code writing self-written - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"WPF (Windows Presentation Foundation) is a powerful UI framework used to develop Windows applications, as part of the .NET Framework. By leveraging WPF, it becomes easy to build complex user interfaces, offering a rich user experience through features such as data binding, animations, styles, and templates. In this article, we will start with the basics &hellip; \ub354 \ubcf4\uae30 \"WPF development, code writing self-written\"","og_url":"https:\/\/atmokpo.com\/w\/37741\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T10:00:03+00:00","article_modified_time":"2024-11-01T11:03:54+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\/37741\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37741\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"WPF development, code writing self-written","datePublished":"2024-11-01T10:00:03+00:00","dateModified":"2024-11-01T11:03:54+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37741\/"},"wordCount":546,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["WPF Programming"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37741\/","url":"https:\/\/atmokpo.com\/w\/37741\/","name":"WPF development, code writing self-written - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T10:00:03+00:00","dateModified":"2024-11-01T11:03:54+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37741\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37741\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37741\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"WPF development, code writing self-written"}]},{"@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\/37741","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=37741"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37741\/revisions"}],"predecessor-version":[{"id":37742,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37741\/revisions\/37742"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}