{"id":37729,"date":"2024-11-01T09:59:57","date_gmt":"2024-11-01T09:59:57","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37729"},"modified":"2024-11-01T11:03:57","modified_gmt":"2024-11-01T11:03:57","slug":"wpf-development-practice-display-products-and-details","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37729\/","title":{"rendered":"WPF Development, Practice Display Products and Details"},"content":{"rendered":"<p><body><\/p>\n<p>\n    WPF (Windows Presentation Foundation) is a powerful UI framework based on the .NET Framework. It is particularly well-suited for developing desktop applications. In this course, we will learn how to display product lists and information details using WPF. Topics covered in this course include product data binding, implementing the MVVM (Model-View-ViewModel) pattern, and UI design using XAML.\n<\/p>\n<h2>1. Preparation Tasks<\/h2>\n<p>\n    To create a WPF application, you must first install Visual Studio and create a new WPF application project. Let&#8217;s set up the new project by following the steps below.\n<\/p>\n<ol>\n<li>Launch Visual Studio.<\/li>\n<li>In the File menu, select <code>New<\/code> -&gt; <code>Project<\/code>.<\/li>\n<li>From the project templates, select <code>WPF App (.NET Core)<\/code> or <code>WPF App (.NET Framework)<\/code>.<\/li>\n<li>Specify the project name and storage path, then click <code>Create<\/code>.<\/li>\n<\/ol>\n<h2>2. Understanding the MVVM Pattern<\/h2>\n<p>\n    The MVVM (Model-View-ViewModel) pattern is an architecture pattern primarily used in WPF that helps to separate the user interface (UI) from business logic. The three components of this pattern are as follows:\n<\/p>\n<ul>\n<li><strong>Model<\/strong>: Business logic and data.<\/li>\n<li><strong>View<\/strong>: User interface.<\/li>\n<li><strong>ViewModel<\/strong>: Mediator between View and Model.<\/li>\n<\/ul>\n<p>\n    In this course, we will create a simple product information application while applying the MVVM pattern.\n<\/p>\n<h2>3. Creating Data Model<\/h2>\n<p>\n    First, let&#8217;s create a <code>Product<\/code> class to hold product information. This class will have properties for the product&#8217;s name, price, and description.\n<\/p>\n<pre class=\"example\">\n<code>using System.ComponentModel;\n\npublic class Product : INotifyPropertyChanged\n{\n    private string _name;\n    private decimal _price;\n    private string _description;\n\n    public string Name\n    {\n        get =&gt; _name;\n        set\n        {\n            _name = value;\n            OnPropertyChanged(nameof(Name));\n        }\n    }\n\n    public decimal Price\n    {\n        get =&gt; _price;\n        set\n        {\n            _price = value;\n            OnPropertyChanged(nameof(Price));\n        }\n    }\n\n    public string Description\n    {\n        get =&gt; _description;\n        set\n        {\n            _description = value;\n            OnPropertyChanged(nameof(Description));\n        }\n    }\n\n    public event PropertyChangedEventHandler PropertyChanged;\n    protected virtual void OnPropertyChanged(string propertyName)\n    {\n        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\n    }\n}\n<\/code>\n<\/pre>\n<p>\n    The above code implements the <code>INotifyPropertyChanged<\/code> interface to allow notifications when properties change. This is useful for data binding.\n<\/p>\n<h2>4. Creating ViewModel<\/h2>\n<p>\n    Next, we will create a <code>ProductViewModel<\/code> class to implement the logic that manages the product list. This ViewModel includes a list of products and displays the details of the selected product.\n<\/p>\n<pre class=\"example\">\n<code>using System.Collections.ObjectModel;\nusing System.Windows.Input;\n\npublic class ProductViewModel : INotifyPropertyChanged\n{\n    private Product _selectedProduct;\n\n    public ObservableCollection&lt;Product&gt; Products { get; }\n\n    public Product SelectedProduct\n    {\n        get =&gt; _selectedProduct;\n        set\n        {\n            _selectedProduct = value;\n            OnPropertyChanged(nameof(SelectedProduct));\n        }\n    }\n\n    public ProductViewModel()\n    {\n        Products = new ObservableCollection&lt;Product&gt;\n        {\n            new Product { Name = \"Laptop\", Price = 1200000, Description = \"High-performance laptop.\" },\n            new Product { Name = \"Smartphone\", Price = 800000, Description = \"Latest smartphone.\" },\n            new Product { Name = \"Tablet\", Price = 500000, Description = \"Portable tablet.\" }\n        };\n    }\n\n    public event PropertyChangedEventHandler PropertyChanged;\n    protected virtual void OnPropertyChanged(string propertyName)\n    {\n        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\n    }\n}\n<\/code>\n<\/pre>\n<p>\n    Here, we use <code>ObservableCollection&lt;Product&gt;<\/code> to manage the product list. ObservableCollection automatically reflects changes in the collection in the UI.\n<\/p>\n<h2>5. UI Design Using XAML<\/h2>\n<p>\n    Now, let&#8217;s design the user interface using XAML. We will bind the UI with the <code>ProductViewModel<\/code> created earlier.\n<\/p>\n<pre class=\"example\">\n<code>&lt;Window x:Class=\"ProductApp.MainWindow\"\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n        Title=\"Product List\" Height=\"350\" Width=\"525\"&gt;\n    &lt;Window.DataContext&gt;\n        &lt;local:ProductViewModel \/&gt;\n    &lt;\/Window.DataContext&gt;\n\n    &lt;Grid&gt;\n        &lt;Grid.ColumnDefinitions&gt;\n            &lt;ColumnDefinition Width=\"2*\"\/&gt;\n            &lt;ColumnDefinition Width=\"3*\"\/&gt;\n        &lt;\/Grid.ColumnDefinitions&gt;\n\n        &lt;ListBox ItemsSource=\"{Binding Products}\" \n                 SelectedItem=\"{Binding SelectedProduct}\" \n                 DisplayMemberPath=\"Name\" \n                 Margin=\"10\" \/&gt;\n\n        &lt;StackPanel Grid.Column=\"1\" Margin=\"10\"&gt;\n            &lt;TextBlock Text=\"Product Name:\" FontWeight=\"Bold\"\/&gt;\n            &lt;TextBlock Text=\"{Binding SelectedProduct.Name}\" \/&gt;\n\n            &lt;TextBlock Text=\"Price:\" FontWeight=\"Bold\"\/&gt;\n            &lt;TextBlock Text=\"{Binding SelectedProduct.Price, StringFormat={}{0:C}}\" \/&gt;\n\n            &lt;TextBlock Text=\"Description:\" FontWeight=\"Bold\"\/&gt;\n            &lt;TextBlock Text=\"{Binding SelectedProduct.Description}\" TextWrapping=\"Wrap\" \/&gt;\n        &lt;\/StackPanel&gt;\n\n    &lt;\/Grid&gt;\n&lt;\/Window&gt;\n<\/code>\n<\/pre>\n<p>\n    The above XAML code sets up a basic layout and uses a ListBox to display the product list. When a user selects a product from the ListBox, the details of the selected product are displayed in the right area.\n<\/p>\n<h2>6. Running the Application and Checking Results<\/h2>\n<p>\n    Now that all the code has been written, let&#8217;s run the application to check the results. By pressing the F5 key to run it in debug mode, you will see the UI as shown below.\n<\/p>\n<p><img decoding=\"async\" alt=\"Product List Application\" src=\"example_screenshot.png\"\/><\/p>\n<h2>7. Conclusion<\/h2>\n<p>\n    In this course, we created a simple product list and details application using WPF. By applying the MVVM pattern, we separated Model, View, and ViewModel, enhancing code readability and maintainability. We were able to easily implement the connection between the user interface and business logic by utilizing WPF&#8217;s data binding capabilities.<br \/>\n    I hope this course has enhanced your understanding of fundamental data binding and MVVM in WPF.\n<\/p>\n<p>\n    Moving forward, I encourage you to develop more complex and diverse WPF applications. Utilize the various features of WPF to create even more appealing user interfaces!\n<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WPF (Windows Presentation Foundation) is a powerful UI framework based on the .NET Framework. It is particularly well-suited for developing desktop applications. In this course, we will learn how to display product lists and information details using WPF. Topics covered in this course include product data binding, implementing the MVVM (Model-View-ViewModel) pattern, and UI design &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37729\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;WPF Development, Practice Display Products and Details&#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-37729","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, Practice Display Products and Details - \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\/37729\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WPF Development, Practice Display Products and Details - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"WPF (Windows Presentation Foundation) is a powerful UI framework based on the .NET Framework. It is particularly well-suited for developing desktop applications. In this course, we will learn how to display product lists and information details using WPF. Topics covered in this course include product data binding, implementing the MVVM (Model-View-ViewModel) pattern, and UI design &hellip; \ub354 \ubcf4\uae30 &quot;WPF Development, Practice Display Products and Details&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37729\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:59:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:03:57+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\/37729\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37729\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"WPF Development, Practice Display Products and Details\",\"datePublished\":\"2024-11-01T09:59:57+00:00\",\"dateModified\":\"2024-11-01T11:03:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37729\/\"},\"wordCount\":479,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"WPF Programming\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37729\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37729\/\",\"name\":\"WPF Development, Practice Display Products and Details - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:59:57+00:00\",\"dateModified\":\"2024-11-01T11:03:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37729\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37729\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37729\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WPF Development, Practice Display Products and Details\"}]},{\"@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, Practice Display Products and Details - \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\/37729\/","og_locale":"ko_KR","og_type":"article","og_title":"WPF Development, Practice Display Products and Details - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"WPF (Windows Presentation Foundation) is a powerful UI framework based on the .NET Framework. It is particularly well-suited for developing desktop applications. In this course, we will learn how to display product lists and information details using WPF. Topics covered in this course include product data binding, implementing the MVVM (Model-View-ViewModel) pattern, and UI design &hellip; \ub354 \ubcf4\uae30 \"WPF Development, Practice Display Products and Details\"","og_url":"https:\/\/atmokpo.com\/w\/37729\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:59:57+00:00","article_modified_time":"2024-11-01T11:03:57+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\/37729\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37729\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"WPF Development, Practice Display Products and Details","datePublished":"2024-11-01T09:59:57+00:00","dateModified":"2024-11-01T11:03:57+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37729\/"},"wordCount":479,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["WPF Programming"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37729\/","url":"https:\/\/atmokpo.com\/w\/37729\/","name":"WPF Development, Practice Display Products and Details - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:59:57+00:00","dateModified":"2024-11-01T11:03:57+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37729\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37729\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37729\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"WPF Development, Practice Display Products and Details"}]},{"@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\/37729","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=37729"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37729\/revisions"}],"predecessor-version":[{"id":37730,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37729\/revisions\/37730"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}