{"id":37485,"date":"2024-11-01T09:57:57","date_gmt":"2024-11-01T09:57:57","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=37485"},"modified":"2024-11-01T11:02:32","modified_gmt":"2024-11-01T11:02:32","slug":"uwp-development-understanding-the-view-in-the-mvvm-programming-pattern","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/37485\/","title":{"rendered":"UWP Development: Understanding the View in the MVVM Programming Pattern"},"content":{"rendered":"<p>Windows Universal Platform (UWP) application development has become an important part of software development in the 21st century. Microsoft has enabled developers to create applications that can run on various Windows 10 devices through UWP. The MVVM (Model-View-ViewModel) architectural pattern is recognized as a key design pattern in UWP application development. In this article, we will explore the concept of &#8216;view&#8217; in UWP applications based on the MVVM pattern and understand it in depth through practical examples.<\/p>\n<h2>Introduction to MVVM Pattern<\/h2>\n<p>The MVVM pattern separates the structure of the application so that each component can be developed, tested, and maintained independently. Here is a brief description of each component of MVVM:<\/p>\n<ul>\n<li><strong>Model:<\/strong> Defines data and business logic. It encompasses all data used by the application and the rules for manipulating that data.<\/li>\n<li><strong>View:<\/strong> Defines the user interface. All UI elements that the user can see are defined here.<\/li>\n<li><strong>ViewModel:<\/strong> Acts as an intermediary between the Model and View, providing data required by the View and handling user input. The View is bound to the ViewModel to display data.<\/li>\n<\/ul>\n<h2>Understanding the View<\/h2>\n<p>In the MVVM pattern, the &#8216;view&#8217; comprises the parts of the application\u2019s user interface that includes all elements interacting with the user. In UWP, the view is defined using XAML (eXtensible Application Markup Language). XAML allows for the declarative definition of UI elements.<\/p>\n<p>The view plays a crucial role not only in encompassing UI elements but also in processing user input and structuring elements that users will see. Here are the main characteristics of the view in UWP:<\/p>\n<ul>\n<li><strong>Data Binding:<\/strong> The view is bound to the properties of the ViewModel, allowing for easy interaction between data and the UI.<\/li>\n<li><strong>Styles and Templates:<\/strong> UWP provides various styles and templates, enabling developers to easily customize the UI.<\/li>\n<li><strong>Commands:<\/strong> The view can use commands from the ViewModel to handle interactions with the user.<\/li>\n<\/ul>\n<h2>Example: View in UWP Application<\/h2>\n<p>Now, let&#8217;s look at a simple example of how to implement the view in a UWP application according to the MVVM pattern. In the example below, we will create a simple counter app.<\/p>\n<h3>1. Create Model<\/h3>\n<pre>\n<code>\npublic class CounterModel\n{\n    public int Value { get; set; }\n\n    public CounterModel()\n    {\n        Value = 0;\n    }\n\n    public void Increment()\n    {\n        Value++;\n    }\n\n    public void Decrement()\n    {\n        Value--;\n    }\n}\n<\/code>\n<\/pre>\n<h3>2. Create ViewModel<\/h3>\n<pre>\n<code>\nusing System.ComponentModel;\nusing System.Windows.Input;\n\npublic class CounterViewModel : INotifyPropertyChanged\n{\n    private readonly CounterModel _model;\n\n    public int CounterValue\n    {\n        get { return _model.Value; }\n        set \n        {\n            _model.Value = value;\n            OnPropertyChanged(nameof(CounterValue));\n        }\n    }\n\n    public ICommand IncrementCommand { get; }\n    public ICommand DecrementCommand { get; }\n\n    public CounterViewModel()\n    {\n        _model = new CounterModel();\n        IncrementCommand = new RelayCommand(Increment);\n        DecrementCommand = new RelayCommand(Decrement);\n    }\n\n    private void Increment()\n    {\n        _model.Increment();\n        CounterValue = _model.Value;\n    }\n\n    private void Decrement()\n    {\n        _model.Decrement();\n        CounterValue = _model.Value;\n    }\n\n    public event PropertyChangedEventHandler PropertyChanged;\n\n    protected virtual void OnPropertyChanged(string propertyName)\n    {\n        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\n    }\n}\n<\/code>\n<\/pre>\n<h3>3. Create View (XAML)<\/h3>\n<pre>\n<code>\n<page mc:ignorable=\"d\" x:class=\"CounterApp.MainPage\" xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\" xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\" xmlns:local=\"using:CounterApp\" xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\" xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\">\n\n    <grid>\n        <textblock fontsize=\"48\" horizontalalignment=\"Center\" text=\"{Binding CounterValue}\" verticalalignment=\"Center\"><\/textblock>\n        <stackpanel horizontalalignment=\"Center\" orientation=\"Horizontal\" verticalalignment=\"Bottom\">\n            <button command=\"{Binding IncrementCommand}\" content=\"Increment\" height=\"50\" margin=\"10\" width=\"100\"><\/button>\n            <button command=\"{Binding DecrementCommand}\" content=\"Decrement\" height=\"50\" margin=\"10\" width=\"100\"><\/button>\n        <\/stackpanel>\n    <\/grid>\n<\/page>\n<\/code>\n<\/pre>\n<h3>4. Binding ViewModel in App.xaml.cs<\/h3>\n<pre>\n<code>\npublic App()\n{\n    this.InitializeComponent();\n    this.Suspending += OnSuspending;\n}\n\nprotected override void OnLaunched(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        var viewModel = new CounterViewModel();\n        rootFrame.Navigate(typeof(MainPage), viewModel);\n    }\n\n    Window.Current.Activate();\n}\n<\/code>\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>In the MVVM pattern, the &#8216;view&#8217; is a core component of the user interface and plays a significant role in shaping user experience. We learned how to define views using XAML in UWP and handle user interaction through ViewModel and data binding. Through this example, we hope to provide a foundation for understanding the basic MVVM pattern and applying such structures in more complex UWP applications.<\/p>\n<p>The world of UWP development is vast and filled with diverse possibilities, and the MVVM architecture greatly helps maximize that potential. We encourage you to continuously practice and gain deeper understanding through various examples.<\/p>\n<p>If you have any further questions or need assistance, please feel free to leave a comment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows Universal Platform (UWP) application development has become an important part of software development in the 21st century. Microsoft has enabled developers to create applications that can run on various Windows 10 devices through UWP. The MVVM (Model-View-ViewModel) architectural pattern is recognized as a key design pattern in UWP application development. In this article, we &hellip; <a href=\"https:\/\/atmokpo.com\/w\/37485\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;UWP Development: Understanding the View in the MVVM Programming Pattern&#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-37485","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: Understanding the View in the MVVM Programming Pattern - \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\/37485\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UWP Development: Understanding the View in the MVVM Programming Pattern - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Windows Universal Platform (UWP) application development has become an important part of software development in the 21st century. Microsoft has enabled developers to create applications that can run on various Windows 10 devices through UWP. The MVVM (Model-View-ViewModel) architectural pattern is recognized as a key design pattern in UWP application development. In this article, we &hellip; \ub354 \ubcf4\uae30 &quot;UWP Development: Understanding the View in the MVVM Programming Pattern&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/37485\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:57:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:02:32+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\/37485\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37485\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"UWP Development: Understanding the View in the MVVM Programming Pattern\",\"datePublished\":\"2024-11-01T09:57:57+00:00\",\"dateModified\":\"2024-11-01T11:02:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37485\/\"},\"wordCount\":490,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"UWP Programming\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/37485\/\",\"url\":\"https:\/\/atmokpo.com\/w\/37485\/\",\"name\":\"UWP Development: Understanding the View in the MVVM Programming Pattern - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:57:57+00:00\",\"dateModified\":\"2024-11-01T11:02:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/37485\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/37485\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/37485\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UWP Development: Understanding the View in the MVVM Programming Pattern\"}]},{\"@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: Understanding the View in the MVVM Programming Pattern - \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\/37485\/","og_locale":"ko_KR","og_type":"article","og_title":"UWP Development: Understanding the View in the MVVM Programming Pattern - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Windows Universal Platform (UWP) application development has become an important part of software development in the 21st century. Microsoft has enabled developers to create applications that can run on various Windows 10 devices through UWP. The MVVM (Model-View-ViewModel) architectural pattern is recognized as a key design pattern in UWP application development. In this article, we &hellip; \ub354 \ubcf4\uae30 \"UWP Development: Understanding the View in the MVVM Programming Pattern\"","og_url":"https:\/\/atmokpo.com\/w\/37485\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:57:57+00:00","article_modified_time":"2024-11-01T11:02:32+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\/37485\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/37485\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"UWP Development: Understanding the View in the MVVM Programming Pattern","datePublished":"2024-11-01T09:57:57+00:00","dateModified":"2024-11-01T11:02:32+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/37485\/"},"wordCount":490,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["UWP Programming"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/37485\/","url":"https:\/\/atmokpo.com\/w\/37485\/","name":"UWP Development: Understanding the View in the MVVM Programming Pattern - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:57:57+00:00","dateModified":"2024-11-01T11:02:32+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/37485\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/37485\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/37485\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"UWP Development: Understanding the View in the MVVM Programming Pattern"}]},{"@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\/37485","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=37485"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37485\/revisions"}],"predecessor-version":[{"id":37486,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/37485\/revisions\/37486"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=37485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=37485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=37485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}