{"id":1623,"date":"2024-04-27T20:45:41","date_gmt":"2024-04-27T18:45:41","guid":{"rendered":"https:\/\/easyrevitapi.com\/?p=1623"},"modified":"2024-04-29T10:28:43","modified_gmt":"2024-04-29T08:28:43","slug":"m-v-vm-pattern-for-revit-part-3","status":"publish","type":"post","link":"https:\/\/easyrevitapi.com\/index.php\/2024\/04\/27\/m-v-vm-pattern-for-revit-part-3\/","title":{"rendered":"M-V-VM Pattern for Revit, part 3"},"content":{"rendered":"\n<p>In the previous articles of this <em>three-part series<\/em>, we explored the foundational principles of the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">M<\/mark>odel-<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">V<\/mark>iew-<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">V<\/mark>iew<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">M<\/mark>odel pattern for Revit add-in development. We began constructing <a href=\"https:\/\/easyrevitapi.com\/index.php\/2023\/11\/01\/m-v-vm-pattern-for-revit-part-2\/\" data-type=\"link\" data-id=\"https:\/\/easyrevitapi.com\/index.php\/2023\/11\/01\/m-v-vm-pattern-for-revit-part-2\/\">a simple add-in<\/a> to demonstrate these concepts, such as how to display <strong>Model <\/strong>data to the user.<br><br>As we dive deeper into the specificities of the M-V-VM pattern and the WPF technology, our third and final article will focus on the dynamic interaction between the <strong>View<\/strong> and the <strong>ViewModel <\/strong>layers. This article will guide you through handling user inputs, processing them through the <strong>Model <\/strong>layer, and ultimately displaying the results back in the <strong>View<\/strong>.<\/p>\n\n\n\n<p>We will simplify complex WPF and M-V-VM concepts as we continue our exploration of software architecture. Building on our add-in&#8217;s example, we&#8217;ll continue illustrating some of the key points we&#8217;ve discussed before, such as <span style=\"text-decoration: underline;\">data binding<\/span> and the <span style=\"text-decoration: underline;\">separation of concerns<\/span>.<\/p>\n\n\n\n<p>The entire project setup used in this series can be retrieved on <a href=\"https:\/\/github.com\/M-Youssef-K\/easyrevitapi.com-MVVM-tutorial-series-base-project\">GitHub<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Handling user&#8217;s events<\/h4>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Wall type selection<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"904\" src=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/image-1024x904.png\" alt=\"\" class=\"wp-image-1763\" style=\"width:371px;height:auto\" srcset=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/image-1024x904.png 1024w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/image-300x265.png 300w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/image-768x678.png 768w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/image.png 1445w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As seen in the previous article, we have configured our add-in window&#8217;s ComboBox control to display the Revit model&#8217;s wall types. Now, we need to register the user&#8217;s wall type selection, for the add-in to later process it and return its related width.<\/p>\n\n\n\n<p>As a reminder, the <strong>ViewModel <\/strong>layer is responsible for storing the user&#8217;s selections and handling responses to user events. To record the user&#8217;s choice of wall type from the UI, we&#8217;ll introduce a new field in our <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark> class that we&#8217;ll name <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">_selectedWallType<\/mark>.<\/p>\n\n\n\n<p>Yet, we still need to establish a link between the window&#8217;s Combo Box and this new field. For this purpose, we&#8217;ll use the WPF <span style=\"text-decoration: underline;\">data binding<\/span> feature. Our add-in&#8217;s architecture graphic may then be updated as follows :<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"659\" src=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/0-1024x659.jpg\" alt=\"\" class=\"wp-image-1742\" srcset=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/0-1024x659.jpg 1024w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/0-300x193.jpg 300w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/0-768x495.jpg 768w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/0-1536x989.jpg 1536w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/0-2048x1319.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>To implement data binding, we need to update the window&#8217;s XAML code. We may do so by assigning the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#64a096\" class=\"has-inline-color\">&#8220;{Binding SelectedWallType}&#8221;<\/mark> keyword to the ComboBox&#8217;s <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">SelectedItem <\/mark>property. <\/p>\n\n\n\n<p>Since we&#8217;ve set the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel <\/mark>class as the window&#8217;s data context, the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#64a096\" class=\"has-inline-color\">SelectedWallType<\/mark> keyword refers to the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">SelectedWallType<\/mark>, which is a public property encapsulating the private <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">_selectedWallType<\/mark> field.<br><\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<p class=\"has-text-align-center has-medium-font-size\"><strong><strong>The window\u2019s XAML code<\/strong><\/strong>&nbsp;<em>(Updated)<\/em><\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(74, 193, 207, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#002B36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;Window x:Class=&quot;WallTypesDisplayer.MainWindow&quot;\n             xmlns=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;\n             xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;\n             xmlns:mc=&quot;http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006&quot; \n             xmlns:d=&quot;http:\/\/schemas.microsoft.com\/expression\/blend\/2008&quot; \n             xmlns:local=&quot;clr-namespace:WallTypesDisplayer&quot;\n             mc:Ignorable=&quot;d&quot; \n        \n             Height= &quot;330&quot; \n             Width=&quot;500&quot; \n&gt;\n    &lt;Grid&gt;\n        &lt;ComboBox ItemsSource =&quot;{Binding RevitDocumentWallTypes}&quot; DisplayMemberPath=&quot;Name&quot; SelectedItem=&quot;{Binding SelectedWallType}&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;22&quot; Margin=&quot;206,130,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;232&quot;\/&gt;\n        &lt;Label HorizontalAlignment=&quot;Left&quot; Height=&quot;26&quot; Margin=&quot;206,163,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;232&quot; Foreground=&quot;Black&quot; FontWeight=&quot;SemiBold&quot;\/&gt;\n        &lt;Button Content=&quot;Return type width&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;23&quot; Margin=&quot;202,242,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;153&quot; RenderTransformOrigin=&quot;0.5,0.5&quot;&gt;&lt;\/Button&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;19&quot; Margin=&quot;49,130,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;136&quot; FontWeight=&quot;DemiBold&quot;&gt;&lt;Run Text=&quot;Document &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;w&quot;\/&gt;&lt;Run Text=&quot;all &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;t&quot;\/&gt;&lt;Run Text=&quot;ypes&quot;\/&gt;&lt;Run Text=&quot; :&quot;\/&gt;&lt;\/TextBlock&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;45&quot; Margin=&quot;45,30,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;294&quot; FontSize=&quot;28&quot; FontWeight=&quot;Light&quot;&gt;&lt;Run Text=&quot;W&quot;\/&gt;&lt;Run Text=&quot;all&quot;\/&gt;&lt;Run Text=&quot; types&quot;\/&gt;&lt;Run Text=&quot; &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;width&quot;\/&gt;&lt;\/TextBlock&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;18&quot; Margin=&quot;49,168,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;136&quot; FontWeight=&quot;DemiBold&quot;&gt;&lt;Run Text=&quot;Wall &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;t&quot;\/&gt;&lt;Run Text=&quot;ype&quot;\/&gt;&lt;Run Text=&quot; width &quot;\/&gt;&lt;Run Text=&quot;(mm)&quot;\/&gt;&lt;Run Text=&quot; &quot;\/&gt;&lt;Run Text=&quot;:&quot;\/&gt;&lt;\/TextBlock&gt;\n\n    &lt;\/Grid&gt;\n&lt;\/Window&gt;\n\" style=\"color:#839496;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki solarized-dark\" style=\"background-color: #002B36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Window<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">x:Class<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;WallTypesDisplayer.MainWindow&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:x<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:mc<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:d<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/expression\/blend\/2008&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:local<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;clr-namespace:WallTypesDisplayer&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">mc:Ignorable<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;d&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">= <\/span><span style=\"color: #2AA198\">&quot;330&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;500&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Grid<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">ComboBox<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">ItemsSource<\/span><span style=\"color: #839496\"> =<\/span><span style=\"color: #2AA198\">&quot;{Binding RevitDocumentWallTypes}&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">DisplayMemberPath<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Name&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">SelectedItem<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;{Binding SelectedWallType}&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;22&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;206,130,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;232&quot;<\/span><span style=\"color: #586E75\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Label<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;26&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;206,163,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;232&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Foreground<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Black&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;SemiBold&quot;<\/span><span style=\"color: #586E75\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Button<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Content<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Return type width&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;23&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;202,242,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;153&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">RenderTransformOrigin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;0.5,0.5&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;\/<\/span><span style=\"color: #268BD2\">Button<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;19&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;49,130,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;136&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;DemiBold&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Document &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;w&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;all &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;t&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;ypes&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; :&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;45&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;45,30,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;294&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontSize<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;28&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Light&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;W&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;all&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; types&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;width&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;18&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;49,168,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;136&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;DemiBold&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wall &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;t&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;ype&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; width &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;(mm)&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;:&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #586E75\">&lt;\/<\/span><span style=\"color: #268BD2\">Grid<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #586E75\">&lt;\/<\/span><span style=\"color: #268BD2\">Window<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><br><strong>Returning wall type width<\/strong><\/p>\n\n\n\n<p>When the user selects a wall type, they can retrieve the corresponding width by clicking the &#8216;Return type width&#8217; button. This action will make our add-in process an input <em>(the chosen wall type)<\/em> and display its related output <em>(the wall type&#8217;s width)<\/em> on the window.<\/p>\n\n\n\n<p>Remember that for data to be displayed in a window, it needs to be stored in the <strong>ViewModel <\/strong>layer. For this purpose, we&#8217;ll add a <strong>_selectedWallTypeWidth<\/strong> field to our <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark> class, updated whenever the user selects a wall type and asks for its width.<\/p>\n\n\n\n<p>Additionally, we&#8217;ll introduce a new method, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">UpdateSelectedWallTypeWidth()<\/mark>, in the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel <\/mark>class, which will update the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<strong>_selectedWallTypeWidth<\/strong> field in response to user action.<\/p>\n\n\n\n<p>As we&#8217;ll later see, this method would also trigger logic within the <strong>Model<\/strong> layer. <span style=\"text-decoration: underline;\">This design allows flexibilit<\/span>y<span style=\"text-decoration: underline;\">, and reinforces the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">&#8216;s<\/mark> role as a coordinator between the view and the model.<\/span><\/p>\n\n\n\n<p>The following graphic shows how the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">UpdateSelectedWallTypeWidth()<\/mark> method is launched when the user pushes the &#8220;Return type width&#8221; button :<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"659\" src=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/A-3-1024x659.jpg\" alt=\"\" class=\"wp-image-1668\" srcset=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/A-3-1024x659.jpg 1024w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/A-3-300x193.jpg 300w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/A-3-768x495.jpg 768w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/A-3-1536x989.jpg 1536w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/A-3-2048x1319.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><br>As seen previously, a WPF window is defined by a layout <em>(XAML code)<\/em> and a code-behind <em>(C#)<\/em>. The window&#8217;s code-behind is where we define what shall happen when a window&#8217;s button is pressed. We do this by creating a new <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">MainWindow<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">MainButtonAction()<\/mark> method, which will call the  <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">UpdateSelectedWallTypeWidth<\/mark>() method as the following : <\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(74, 193, 207, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#002B36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"using System.Windows;\nusing WallTypesDisplayer.ProjectViewModel;\nusing Autodesk.Revit.DB;\n\n\nnamespace WallTypesDisplayer\n{\n    public partial class MainWindow : Window\n    {\n        private ViewModel _viewModel;\n        public ViewModel ViewModel { get { return _viewModel; } }\n\n        public MainWindow(ViewModel vModel)\n        {\n            InitializeComponent();\n\n            this._viewModel = vModel;\n            DataContext = this._viewModel;\n        }\n\n        private void MainButtonAction(object sender, RoutedEventArgs e) \n        {\n            this._viewModel.UpdateSelectedWallTypeWidth();\n        }\n    }\n}\n\" style=\"color:#839496;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki solarized-dark\" style=\"background-color: #002B36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #859900\">using<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">System<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">Windows<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #859900\">using<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallTypesDisplayer<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">ProjectViewModel<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #859900\">using<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">Autodesk<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">Revit<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">DB<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #93A1A1; font-weight: bold\">namespace<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallTypesDisplayer<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1; font-weight: bold\">partial<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1; font-weight: bold\">class<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">MainWindow<\/span><span style=\"color: #839496\"> : <\/span><span style=\"color: #CB4B16\">Window<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">ViewModel<\/span><span style=\"color: #839496\"> _viewModel;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">ViewModel<\/span><span style=\"color: #839496\"> ViewModel { <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_viewModel<\/span><span style=\"color: #839496\">; } }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">MainWindow<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #CB4B16\">ViewModel<\/span><span style=\"color: #839496\"> vModel)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">InitializeComponent<\/span><span style=\"color: #839496\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">_viewModel<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">vModel<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">DataContext<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">_viewModel<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">void<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">MainButtonAction<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #859900\">object<\/span><span style=\"color: #839496\"> sender, <\/span><span style=\"color: #CB4B16\">RoutedEventArgs<\/span><span style=\"color: #839496\"> e) <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">_viewModel<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">UpdateSelectedWallTypeWidth<\/span><span style=\"color: #839496\">();<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><br>We then define an <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#7f39ea\" class=\"has-inline-color\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#915edc\" class=\"has-inline-color\">event handler <\/mark><\/strong><\/mark><\/strong>for the window&#8217;s button. This handler is linked to the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">MainButtonAction()<\/mark> method in the window&#8217;s code-behind. We accomplish this by using the <strong>Click <\/strong>attribute in the button\u2019s XAML code, as follows :<br><\/p>\n\n\n\n<p class=\"has-text-align-center has-medium-font-size\"><strong><strong>The window\u2019s XAML code<\/strong><\/strong>&nbsp;<em>(Updated)<\/em><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(74, 193, 207, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#002B36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;Window x:Class=&quot;WallTypesDisplayer.MainWindow&quot;\n             xmlns=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;\n             xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;\n             xmlns:mc=&quot;http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006&quot; \n             xmlns:d=&quot;http:\/\/schemas.microsoft.com\/expression\/blend\/2008&quot; \n             xmlns:local=&quot;clr-namespace:WallTypesDisplayer&quot;\n             mc:Ignorable=&quot;d&quot; \n        \n             Height= &quot;330&quot; \n             Width=&quot;500&quot; \n&gt;\n    &lt;Grid&gt;\n        &lt;ComboBox ItemsSource =&quot;{Binding RevitDocumentWallTypes}&quot; DisplayMemberPath=&quot;Name&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;19&quot; Margin=&quot;206,130,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;232&quot;\/&gt;\n        &lt;Label HorizontalAlignment=&quot;Left&quot; Height=&quot;26&quot; Margin=&quot;206,163,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;232&quot; Foreground=&quot;Black&quot; FontWeight=&quot;SemiBold&quot;\/&gt;\n        &lt;Button Content=&quot;Return type width&quot; Click=&quot;MainButtonAction&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;23&quot; Margin=&quot;202,242,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;153&quot; RenderTransformOrigin=&quot;0.5,0.5&quot;&gt;&lt;\/Button&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;19&quot; Margin=&quot;49,130,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;136&quot; FontWeight=&quot;DemiBold&quot;&gt;&lt;Run Text=&quot;Document &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;w&quot;\/&gt;&lt;Run Text=&quot;all &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;t&quot;\/&gt;&lt;Run Text=&quot;ypes&quot;\/&gt;&lt;Run Text=&quot; :&quot;\/&gt;&lt;\/TextBlock&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;45&quot; Margin=&quot;45,30,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;294&quot; FontSize=&quot;28&quot; FontWeight=&quot;Light&quot;&gt;&lt;Run Text=&quot;W&quot;\/&gt;&lt;Run Text=&quot;all&quot;\/&gt;&lt;Run Text=&quot; types&quot;\/&gt;&lt;Run Text=&quot; &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;width&quot;\/&gt;&lt;\/TextBlock&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;18&quot; Margin=&quot;49,168,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;136&quot; FontWeight=&quot;DemiBold&quot;&gt;&lt;Run Text=&quot;Wall &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;t&quot;\/&gt;&lt;Run Text=&quot;ype&quot;\/&gt;&lt;Run Text=&quot; width &quot;\/&gt;&lt;Run Text=&quot;(mm)&quot;\/&gt;&lt;Run Text=&quot; &quot;\/&gt;&lt;Run Text=&quot;:&quot;\/&gt;&lt;\/TextBlock&gt;\n\n    &lt;\/Grid&gt;\n&lt;\/Window&gt;\" style=\"color:#839496;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki solarized-dark\" style=\"background-color: #002B36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Window<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">x:Class<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;WallTypesDisplayer.MainWindow&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:x<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:mc<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:d<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/expression\/blend\/2008&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:local<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;clr-namespace:WallTypesDisplayer&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">mc:Ignorable<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;d&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">= <\/span><span style=\"color: #2AA198\">&quot;330&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;500&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Grid<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">ComboBox<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">ItemsSource<\/span><span style=\"color: #839496\"> =<\/span><span style=\"color: #2AA198\">&quot;{Binding RevitDocumentWallTypes}&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">DisplayMemberPath<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Name&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;19&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;206,130,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;232&quot;<\/span><span style=\"color: #586E75\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Label<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;26&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;206,163,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;232&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Foreground<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Black&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;SemiBold&quot;<\/span><span style=\"color: #586E75\">\/&gt;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Button<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Content<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Return type width&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Click<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;MainButtonAction&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;23&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;202,242,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;153&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">RenderTransformOrigin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;0.5,0.5&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;\/<\/span><span style=\"color: #268BD2\">Button<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;19&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;49,130,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;136&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;DemiBold&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Document &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;w&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;all &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;t&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;ypes&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; :&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;45&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;45,30,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;294&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontSize<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;28&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Light&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;W&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;all&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; types&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;width&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;18&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;49,168,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;136&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;DemiBold&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wall &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;t&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;ype&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; width &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;(mm)&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;:&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #586E75\">&lt;\/<\/span><span style=\"color: #268BD2\">Grid<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #586E75\">&lt;\/<\/span><span style=\"color: #268BD2\">Window<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Processing the user&#8217;s selection<\/h4>\n\n\n\n<p>So far, we designed an application layout for listening to and handling the user&#8217;s selection and events. Let&#8217;s now see how to design and implement our add-in&#8217;s logic-related parts. <br><br>Let&#8217;s now create a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">WallTypeData<\/mark> class, to handle the retrieval of wall types data. We&#8217;ll also add a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">RetrieveWidth()<\/mark> static method to this class to fetch the width for each specific wall type. Since it processes elements from the Revit database, this method belongs to the <strong>Model<\/strong> layer.<\/p>\n\n\n\n<p>As seen previously, the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">UpdateSelectedWallTypeWidth()<\/mark> method plays a coordinator role between the <strong>View <\/strong>layer <em>(user&#8217;s selection and events)<\/em>, and the <strong>Model <\/strong>layer <em>(The logic that processes the user&#8217;s selection)<\/em>. The following graphic represents this principle :<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"862\" src=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/B-1024x862.jpg\" alt=\"\" class=\"wp-image-1673\" srcset=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/B-1024x862.jpg 1024w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/B-300x253.jpg 300w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/B-768x647.jpg 768w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/B-1536x1293.jpg 1536w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/B-2048x1725.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><br><\/p>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">UpdateSelectedWallTypeWidth()<\/mark> method calls <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">WallTypeData<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">RetrieveWidth()<\/mark> with the user-selected wall type, then stores the returned width value in the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<strong>_selectedWallTypeWidth<\/strong> field for display by the add-in&#8217;s window. <br><br>The principle is that <strong>ViewModel <\/strong>layer methods delegate user selection processing to the <strong>Model<\/strong> layer methods, maintaining a clear separation of concerns. This approach ensures the <strong>ViewModel <\/strong>is an interface that models the <strong>View<\/strong>, <span style=\"text-decoration: underline;\">enhancing modularity and extensibility for future functionalities in our add-in<\/span>.<\/p>\n\n\n\n<p>The <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">WallTypeData<\/mark>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">RetrieveWidth()<\/mark> method could be implemented as following :<\/p>\n\n\n\n<p class=\"has-text-align-center has-medium-font-size\"><br><strong>The WallTypesData<\/strong> <strong>class<\/strong>&nbsp;<em> <\/em>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#002B36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"using System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing Autodesk.Revit.DB;\n\nnamespace WallTypesDisplayer.Model\n{\n    public class WallTypeData\n    {\n        public static double ReturnWidth(WallType wallType) \n        {\n            double WallTypeWidth_Feet = wallType.Width;\n            double WallTypeWidth_Millimeters = WallTypeWidth_Feet * 304.8;\n            return WallTypeWidth_Millimeters;\n        }\n    }\n}\" style=\"color:#839496;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki solarized-dark\" style=\"background-color: #002B36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #859900\">using<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">System<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">Linq<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #859900\">using<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">System<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">Text<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #859900\">using<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">System<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">Threading<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">Tasks<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #859900\">using<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">Autodesk<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">Revit<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">DB<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #93A1A1; font-weight: bold\">namespace<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallTypesDisplayer<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">Model<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1; font-weight: bold\">class<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallTypeData<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1; font-weight: bold\">static<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">double<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">ReturnWidth<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\"> wallType) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #859900\">double<\/span><span style=\"color: #839496\"> WallTypeWidth_Feet <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">wallType<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">Width<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #859900\">double<\/span><span style=\"color: #839496\"> WallTypeWidth_Millimeters <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">WallTypeWidth_Feet<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">*<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #D33682\">304.8<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">WallTypeWidth_Millimeters<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"has-text-align-center has-medium-font-size\"><br><strong>The ViewModel class<\/strong>&nbsp;<em>(Updated)<\/em><br><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(74, 193, 207, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#002B36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"namespace WallTypesDisplayer.ProjectViewModel \n{\n    public class ViewModel\n    {\n        private Document _revitDocument;\n        public Document RevitDocument \n        {\n            get { return _revitDocument; }\n            set { _revitDocument = value; }     \n        }\n\n        private List&lt;WallType&gt; _revitDocumentWallTypes;\n        public List&lt;WallType&gt; RevitDocumentWallTypes\n        {\n            get { return _revitDocumentWallTypes; }\n            set { _revitDocumentWallTypes = value; }\n        }\n\n        private WallType _selectedWallType;\n        public WallType SelectedWallType\n        {\n            get { return _selectedWallType; }\n            set { _selectedWallType = value; }\n        }\n        \n        private double _selectedWallTypeWidth;\n        public double SelectedWallTypeWidth\n        {\n            get { return _selectedWallTypeWidth; }\n            set { _selectedWallTypeWidth = value;}\n        }\n\n        public ViewModel(Document rvtDocument)\n        {\n            this.RevitDocument = rvtDocument;\n            this.RevitDocumentWallTypes = DocumentTypesExtractor.ExtractWallTypes(this.RevitDocument );\n        }\n        \n        public void UpdateSelectedWallTypeWidth()\n        {\n            this.SelectedWallTypeWidth = WallTypeData.ReturnWidth(this.SelectedWallType);\n        }\n        \n    }\n}\" style=\"color:#839496;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki solarized-dark\" style=\"background-color: #002B36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #93A1A1; font-weight: bold\">namespace<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallTypesDisplayer<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">ProjectViewModel<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1; font-weight: bold\">class<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">ViewModel<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">Document<\/span><span style=\"color: #839496\"> _revitDocument;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">Document<\/span><span style=\"color: #839496\"> RevitDocument <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_revitDocument<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">set<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #268BD2\">_revitDocument<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">value<\/span><span style=\"color: #839496\">; }     <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">List<\/span><span style=\"color: #839496\">&lt;<\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\">&gt; _revitDocumentWallTypes;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">List<\/span><span style=\"color: #839496\">&lt;<\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\">&gt; RevitDocumentWallTypes<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_revitDocumentWallTypes<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">set<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #268BD2\">_revitDocumentWallTypes<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">value<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\"> _selectedWallType;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\"> SelectedWallType<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_selectedWallType<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">set<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #268BD2\">_selectedWallType<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">value<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">double<\/span><span style=\"color: #839496\"> _selectedWallTypeWidth;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">double<\/span><span style=\"color: #839496\"> SelectedWallTypeWidth<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_selectedWallTypeWidth<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">set<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #268BD2\">_selectedWallTypeWidth<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">value<\/span><span style=\"color: #839496\">;}<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">ViewModel<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #CB4B16\">Document<\/span><span style=\"color: #839496\"> rvtDocument)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">RevitDocument<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">rvtDocument<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">RevitDocumentWallTypes<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">DocumentTypesExtractor<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">ExtractWallTypes<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">RevitDocument<\/span><span style=\"color: #839496\"> );<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">void<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">UpdateSelectedWallTypeWidth<\/span><span style=\"color: #839496\">()<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">SelectedWallTypeWidth<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">WallTypeData<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">ReturnWidth<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">SelectedWallType<\/span><span style=\"color: #839496\">);<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Displaying wall type&#8217;s width on the window<\/h4>\n\n\n\n<p><br>So far, we retrieved the wall type&#8217;s width and stored it in the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel <\/mark>class. Let&#8217;s finally see how to display this information on our add-in&#8217;s window.<\/p>\n\n\n\n<p>We may use <span style=\"text-decoration: underline;\">data binding<\/span> again to connect the window&#8217;s label, as the UI element that displays information, with the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<strong>_selectedWallTypeWidth <\/strong>field. The following graphic and updated XAML code show this principle :<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"862\" src=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/C-1024x862.jpg\" alt=\"\" class=\"wp-image-1687\" srcset=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/C-1024x862.jpg 1024w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/C-300x253.jpg 300w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/C-768x647.jpg 768w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/C-1536x1293.jpg 1536w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/C-2048x1725.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center has-medium-font-size\"><br><strong><strong>The window\u2019s XAML code<\/strong><\/strong>&nbsp;<em>(Updated)<\/em><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-highlight-hover\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(74, 193, 207, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#002B36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;Window x:Class=&quot;WallTypesDisplayer.MainWindow&quot;\n             xmlns=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;\n             xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;\n             xmlns:mc=&quot;http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006&quot; \n             xmlns:d=&quot;http:\/\/schemas.microsoft.com\/expression\/blend\/2008&quot; \n             xmlns:local=&quot;clr-namespace:WallTypesDisplayer&quot;\n             mc:Ignorable=&quot;d&quot; \n        \n             Height= &quot;330&quot; \n             Width=&quot;500&quot; \n&gt;\n    &lt;Grid&gt;\n        &lt;ComboBox ItemsSource =&quot;{Binding RevitDocumentWallTypes}&quot; SelectedItem=&quot;{Binding SelectedWallType}&quot; DisplayMemberPath=&quot;Name&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;22&quot; Margin=&quot;206,130,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;232&quot;\/&gt;\n        &lt;Label Content=&quot;{Binding SelectedWallTypeWidth}&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;26&quot; Margin=&quot;206,163,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;232&quot; Foreground=&quot;Black&quot; FontWeight=&quot;SemiBold&quot;\/&gt;\n        &lt;Button Content=&quot;Return type width&quot; Click=&quot;MainButtonAction&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;23&quot; Margin=&quot;202,242,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;153&quot; RenderTransformOrigin=&quot;0.5,0.5&quot;&gt;&lt;\/Button&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;19&quot; Margin=&quot;49,130,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;136&quot; FontWeight=&quot;DemiBold&quot;&gt;&lt;Run Text=&quot;Document &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;w&quot;\/&gt;&lt;Run Text=&quot;all &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;t&quot;\/&gt;&lt;Run Text=&quot;ypes&quot;\/&gt;&lt;Run Text=&quot; :&quot;\/&gt;&lt;\/TextBlock&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;45&quot; Margin=&quot;45,30,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;294&quot; FontSize=&quot;28&quot; FontWeight=&quot;Light&quot;&gt;&lt;Run Text=&quot;W&quot;\/&gt;&lt;Run Text=&quot;all&quot;\/&gt;&lt;Run Text=&quot; types&quot;\/&gt;&lt;Run Text=&quot; &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;width&quot;\/&gt;&lt;\/TextBlock&gt;\n        &lt;TextBlock HorizontalAlignment=&quot;Left&quot; Height=&quot;18&quot; Margin=&quot;49,168,0,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;136&quot; FontWeight=&quot;DemiBold&quot;&gt;&lt;Run Text=&quot;Wall &quot;\/&gt;&lt;Run Language=&quot;fr-fr&quot; Text=&quot;t&quot;\/&gt;&lt;Run Text=&quot;ype&quot;\/&gt;&lt;Run Text=&quot; width &quot;\/&gt;&lt;Run Text=&quot;(mm)&quot;\/&gt;&lt;Run Text=&quot; &quot;\/&gt;&lt;Run Text=&quot;:&quot;\/&gt;&lt;\/TextBlock&gt;\n\n    &lt;\/Grid&gt;\n&lt;\/Window&gt;\n\" style=\"color:#839496;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki solarized-dark\" style=\"background-color: #002B36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Window<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">x:Class<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;WallTypesDisplayer.MainWindow&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:x<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:mc<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:d<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;http:\/\/schemas.microsoft.com\/expression\/blend\/2008&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">xmlns:local<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;clr-namespace:WallTypesDisplayer&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">mc:Ignorable<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;d&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">= <\/span><span style=\"color: #2AA198\">&quot;330&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">             <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;500&quot;<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Grid<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">ComboBox<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">ItemsSource<\/span><span style=\"color: #839496\"> =<\/span><span style=\"color: #2AA198\">&quot;{Binding RevitDocumentWallTypes}&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">SelectedItem<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;{Binding SelectedWallType}&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">DisplayMemberPath<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Name&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;22&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;206,130,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;232&quot;<\/span><span style=\"color: #586E75\">\/&gt;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Label<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Content<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;{Binding SelectedWallTypeWidth}&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;26&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;206,163,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;232&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Foreground<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Black&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;SemiBold&quot;<\/span><span style=\"color: #586E75\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">Button<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Content<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Return type width&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Click<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;MainButtonAction&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;23&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;202,242,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;153&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">RenderTransformOrigin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;0.5,0.5&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;\/<\/span><span style=\"color: #268BD2\">Button<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;19&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;49,130,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;136&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;DemiBold&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Document &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;w&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;all &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;t&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;ypes&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; :&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;45&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;45,30,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;294&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontSize<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;28&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Light&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;W&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;all&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; types&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;width&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #586E75\">&lt;<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">HorizontalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Left&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Height<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;18&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Margin<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;49,168,0,0&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">TextWrapping<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wrap&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">VerticalAlignment<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Top&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Width<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;136&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">FontWeight<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;DemiBold&quot;<\/span><span style=\"color: #586E75\">&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;Wall &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Language<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;fr-fr&quot;<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;t&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;ype&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; width &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;(mm)&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot; &quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;<\/span><span style=\"color: #268BD2\">Run<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1\">Text<\/span><span style=\"color: #839496\">=<\/span><span style=\"color: #2AA198\">&quot;:&quot;<\/span><span style=\"color: #586E75\">\/&gt;&lt;\/<\/span><span style=\"color: #268BD2\">TextBlock<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    <\/span><span style=\"color: #586E75\">&lt;\/<\/span><span style=\"color: #268BD2\">Grid<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #586E75\">&lt;\/<\/span><span style=\"color: #268BD2\">Window<\/span><span style=\"color: #586E75\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><br><\/p>\n\n\n\n<p>The highlighted line in the XAML code above establishes data binding between the window&#8217;s Label and the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark>.<strong>_selectedWallTypeWidth<\/strong> field, by assigning the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#64a098\" class=\"has-inline-color\">&#8220;{Binding SelectedWallTypeWidth}&#8221;<\/mark> to the Label&#8217;s <strong>Content<\/strong> property. The add-in&#8217;s window is now connected and &#8220;listens&#8221; to the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark> class. <\/p>\n\n\n\n<p>We would also like the window to be automatically updated each time the user asks for another wall type. We need to set up an automated process for this purpose, by having the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel <\/mark>class implement the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#46863d\" class=\"has-inline-color\">INotifyPropertyChanged <\/mark>interface.<br><br><span style=\"text-decoration: underline;\">In object-oriented programming, an interface is a set of functionalities that form a contract allowing different parts of an application to communicate<\/span>. Such contract makes a class have certain methods and properties necessary to exchange data with other code parts. Let&#8217;s see the updated version of the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel <\/mark>class to understand this principle :<\/p>\n\n\n\n<p class=\"has-text-align-center has-medium-font-size\"><br><strong>The ViewModel class<\/strong>&nbsp;<em>(Updated)<\/em><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-highlight-color:rgba(74, 193, 207, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#002B36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"namespace WallTypesDisplayer.ProjectViewModel \n{\n    public class ViewModel : INotifyPropertyChanged\n    {\n        public event PropertyChangedEventHandler PropertyChanged;\n\n        private Document _revitDocument;\n        public Document RevitDocument \n        {\n            get { return _revitDocument; }\n            set { _revitDocument = value; }     \n        }\n\n        private List&lt;WallType&gt; _revitDocumentWallTypes;\n        public List&lt;WallType&gt; RevitDocumentWallTypes\n        {\n            get { return _revitDocumentWallTypes; }\n            set { _revitDocumentWallTypes = value; }\n        }\n\n        private WallType _selectedWallType;\n        public WallType SelectedWallType\n        {\n            get { return _selectedWallType; }\n            set { _selectedWallType = value; }\n        }\n\n        private double _selectedWallTypeWidth;\n        public double SelectedWallTypeWidth\n        {\n            get { return _selectedWallTypeWidth; }\n            set\n            {\n                _selectedWallTypeWidth = value;\n                OnPropertyChanged();\n            }\n        }\n\n        public ViewModel(Document rvtDocument)\n        {\n            this.RevitDocument = rvtDocument;\n            this.RevitDocumentWallTypes = DocumentTypesExtractor.ExtractWallTypes(rvtDocument);\n        }\n\n        public void UpdateSelectedWallTypeWidth()\n        {\n            this.SelectedWallTypeWidth = WallTypeData.ReturnWidth(this.SelectedWallType);\n        }\n\n        private void OnPropertyChanged([CallerMemberName] string propertyName = null)\n        {\n            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\n        }\n    }\n}\n\n\n\n\" style=\"color:#839496;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki solarized-dark\" style=\"background-color: #002B36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #93A1A1; font-weight: bold\">namespace<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallTypesDisplayer<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #CB4B16\">ProjectViewModel<\/span><span style=\"color: #839496\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">{<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">    <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1; font-weight: bold\">class<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">ViewModel<\/span><span style=\"color: #839496\"> : <\/span><span style=\"color: #CB4B16\">INotifyPropertyChanged<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #93A1A1; font-weight: bold\">event<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">PropertyChangedEventHandler<\/span><span style=\"color: #839496\"> PropertyChanged;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">Document<\/span><span style=\"color: #839496\"> _revitDocument;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">Document<\/span><span style=\"color: #839496\"> RevitDocument <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_revitDocument<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">set<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #268BD2\">_revitDocument<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">value<\/span><span style=\"color: #839496\">; }     <\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">List<\/span><span style=\"color: #839496\">&lt;<\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\">&gt; _revitDocumentWallTypes;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">List<\/span><span style=\"color: #839496\">&lt;<\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\">&gt; RevitDocumentWallTypes<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_revitDocumentWallTypes<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">set<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #268BD2\">_revitDocumentWallTypes<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">value<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\"> _selectedWallType;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">WallType<\/span><span style=\"color: #839496\"> SelectedWallType<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_selectedWallType<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">set<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #268BD2\">_selectedWallType<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">value<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">double<\/span><span style=\"color: #839496\"> _selectedWallTypeWidth;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">double<\/span><span style=\"color: #839496\"> SelectedWallTypeWidth<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">get<\/span><span style=\"color: #839496\"> { <\/span><span style=\"color: #859900\">return<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">_selectedWallTypeWidth<\/span><span style=\"color: #839496\">; }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #93A1A1; font-weight: bold\">set<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">                <\/span><span style=\"color: #268BD2\">_selectedWallTypeWidth<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">value<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">                <\/span><span style=\"color: #268BD2\">OnPropertyChanged<\/span><span style=\"color: #839496\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">ViewModel<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #CB4B16\">Document<\/span><span style=\"color: #839496\"> rvtDocument)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">RevitDocument<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">rvtDocument<\/span><span style=\"color: #839496\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">RevitDocumentWallTypes<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">DocumentTypesExtractor<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">ExtractWallTypes<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #268BD2\">rvtDocument<\/span><span style=\"color: #839496\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">public<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">void<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">UpdateSelectedWallTypeWidth<\/span><span style=\"color: #839496\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">SelectedWallTypeWidth<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">WallTypeData<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">ReturnWidth<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">SelectedWallType<\/span><span style=\"color: #839496\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        <\/span><span style=\"color: #93A1A1; font-weight: bold\">private<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #859900\">void<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #268BD2\">OnPropertyChanged<\/span><span style=\"color: #839496\">([<\/span><span style=\"color: #CB4B16\">CallerMemberName<\/span><span style=\"color: #839496\">] <\/span><span style=\"color: #859900\">string<\/span><span style=\"color: #839496\"> propertyName <\/span><span style=\"color: #859900\">=<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #B58900\">null<\/span><span style=\"color: #839496\">)<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        {<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">            <\/span><span style=\"color: #268BD2\">PropertyChanged<\/span><span style=\"color: #859900\">?<\/span><span style=\"color: #839496\">.<\/span><span style=\"color: #268BD2\">Invoke<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #268BD2\">this<\/span><span style=\"color: #839496\">, <\/span><span style=\"color: #859900\">new<\/span><span style=\"color: #839496\"> <\/span><span style=\"color: #CB4B16\">PropertyChangedEventArgs<\/span><span style=\"color: #839496\">(<\/span><span style=\"color: #268BD2\">propertyName<\/span><span style=\"color: #839496\">));<\/span><\/span>\n<span class=\"line cbp-line-highlight\"><span style=\"color: #839496\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #839496\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><br><\/p>\n\n\n\n<p>Implementing the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#46863d\" class=\"has-inline-color\">INotifyPropertyChanged <\/mark>interface adds the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#bf11b1\" class=\"has-inline-color\">PropertyChanged <\/mark>event<strong> <\/strong>the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel <\/mark>class. As its name suggests, an event is a functionality that allows a class to inform another class about something significant that is happening or has happened in the context of the application. <\/p>\n\n\n\n<p>In our case, the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#bf11b1\" class=\"has-inline-color\">PropertyChanged<\/mark> event will be triggered once the public <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-6-color\">SelectedWallTypeWidth  <\/mark>property of the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark> object is updated. The use of this event ensures that such change is communicated to and reflected in the add-in&#8217;s window, promoting a dynamic and responsive application.<\/p>\n\n\n\n<p>To sum up, when the user selects a new wall type and asks for its width, the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel <\/mark>object updates its states and informs the window about it by sending a message : <span style=\"text-decoration: underline;\">the event is raised<\/span>. The window listens to the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel<\/mark> object and updates the information it displays accordingly.<\/p>\n\n\n\n<p>Finally, we implement the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-3-color\">OnPropertyChanged()<\/mark> method, which simplifies the process of triggering the <mark style=\"background-color:rgba(0, 0, 0, 0);color:#bf11b1\" class=\"has-inline-color\">PropertyChanged<\/mark> event. This method is called in the setter of each public property of the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-palette-color-1-color\">ViewModel <\/mark>class, therefore updating the window whenever that property&#8217;s value is changed.<\/p>\n\n\n\n<p>Now we have set up our M-V-VM add-in&#8217;s architecture, and obtain the following UI that gets updated each time the user selects a new wall type.<br><br><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"691\" src=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/Screenshot-1024x691.jpg\" alt=\"\" class=\"wp-image-1689\" style=\"width:423px;height:auto\" srcset=\"https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/Screenshot-1024x691.jpg 1024w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/Screenshot-300x202.jpg 300w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/Screenshot-768x518.jpg 768w, https:\/\/easyrevitapi.com\/wp-content\/uploads\/2024\/04\/Screenshot.jpg 1291w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p>Throughout this series, we&#8217;ve covered key aspects of the M-V-VM architecture, showing its effectiveness in guiding the development process. By assigning specific responsibilities within the application, updates become more manageable.<\/p>\n\n\n\n<p>This series sets the stage for deeper explorations into the Revit add-ins development, and more generally into software design and architecture. As it wraps up, the path forward remains filled with opportunities to apply and expand upon the principles discussed. The potential for enhancing software functionality and user interaction for Autodesk Revit is vast.<\/p>\n\n\n\n<p>I hope this content will be valuable to you. Keep on pushing the boundaries and exploring new possibilities, and remember to connect at <a>m-youssef@easyrevitapi.com<\/a> for any further discussion.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous articles of this three-part series, we explored the foundational principles of the Model-View-ViewModel pattern for Revit add-in development. We began constructing a simple add-in to demonstrate these concepts, such as how to display Model data to the user. As we dive deeper into the specificities of the M-V-VM pattern and the WPF [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1819,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-design"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/posts\/1623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/comments?post=1623"}],"version-history":[{"count":154,"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/posts\/1623\/revisions"}],"predecessor-version":[{"id":1815,"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/posts\/1623\/revisions\/1815"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/media\/1819"}],"wp:attachment":[{"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/media?parent=1623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/categories?post=1623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/easyrevitapi.com\/index.php\/wp-json\/wp\/v2\/tags?post=1623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}