{"id":205,"date":"2021-02-18T15:13:33","date_gmt":"2021-02-18T07:13:33","guid":{"rendered":"https:\/\/www.tonghin.com.my\/blog\/?p=205"},"modified":"2021-02-18T15:13:36","modified_gmt":"2021-02-18T07:13:36","slug":"disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode","status":"publish","type":"post","link":"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/","title":{"rendered":"Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode"},"content":{"rendered":"\n<p>To begin the week, I will be fixing bug in Service class by refactor small changes on implementation. My objective is changing <code><sub><sup>Read()<\/sup><\/sub><\/code> to <code><sub><sup>Get()<\/sup><\/sub><\/code> on certain variable in update method. As this variable only has existing Read function, I then added <code><sub><sup>Collection&lt;Variables> GetVariables<\/sup><\/sub><\/code> in Repository class. Hence, I change <code><sub><sup>ReadVariables()<\/sup><\/sub><\/code> to <code><sub><sup>GetVariables()<\/sup><\/sub><\/code> for update\/edit\/delete and any function that will make changes on the value of this variable. <br><br>In the progress, we bump into an issue, where we still able to input despite in detail view mode. This is a serious bug, as any changes would be updated\/saved when ReadyToPick is triggered. Thus, we came up with a idea after discussing the issue. I need to set all input\/controls to IsReadOnly and disable them. In order to do that, I need to alter code in DetailView XAML class and add new properties in DetailViewModel class.<br><br>As an alternative, I add <code><sub><sup>IsEnabled = \"{Binding IsControlEnabled}\"<\/sup><\/sub><\/code> and <code><sub><sup>IsReadOnly= \"{Binding IsControlReadOnly}\"<\/sup><\/sub><\/code> for relevant controls. While in DetailViewModel, I introduced two properties which is <code><sub><sup>IsControlEnabled <\/sup><\/sub><\/code>with default value true and <code><sub><sup>IsControlReadOnly <\/sup><\/sub><\/code>with default value false. I then perform logic of <code><sub><sup>IsControlEnabled = false <\/sup><\/sub><\/code>and <code><sub><sup>IsControlReadOnly = true<\/sup><\/sub><\/code> under view mode, making user unable to make changes on all controls. <br><br>However, there is a grid data textbox, buttons and combo box that is not set to disable &amp; read only simply by using above method. It happens that I need to link it to ancestor of data grid such as below:<br><code><sub><sup>i) IsEnabled=\"{Binding DataContext.IsControlEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}\"<br>ii) IsReadOnly=\"{Binding DataContext.IsControlReadOnly, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}\"<\/sup><\/sub><\/code><br><br>After code is altered, system user could use ReadyToPick without able to edit them in view mode. (In edit mode, user able to make changes but ReadyToPick button is disable). Hence, the bug fixed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To begin the week, I will be fixing bug in Service class by refactor small changes on implementation. My objective is changing Read() to Get() on certain variable in update method. As this variable only has existing Read function, I then added Collection&lt;Variables> GetVariables in Repository class. Hence, I change ReadVariables() to GetVariables() for update\/edit\/delete &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[10],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode | Tong Hin&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode | Tong Hin&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"To begin the week, I will be fixing bug in Service class by refactor small changes on implementation. My objective is changing Read() to Get() on certain variable in update method. As this variable only has existing Read function, I then added Collection&lt;Variables&gt; GetVariables in Repository class. Hence, I change ReadVariables() to GetVariables() for update\/edit\/delete &hellip; Continue reading &quot;Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/\" \/>\n<meta property=\"og:site_name\" content=\"Tong Hin&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-18T07:13:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-18T07:13:36+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\",\"name\":\"TONG HIN MACHINERY\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"sameAs\":[\"https:\/\/www.youtube.com\/channel\/UC60EoxJMNbu8mV0LuEGfrBg\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/wp-content\/uploads\/2020\/10\/web_logo_180_180.jpg\",\"width\":180,\"height\":180,\"caption\":\"TONG HIN MACHINERY\"},\"image\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#website\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"name\":\"Tong Hin&#039;s Blog\",\"description\":\"Sharing About Technology\",\"publisher\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.tonghin.com.my\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/#webpage\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/\",\"name\":\"Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode | Tong Hin&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#website\"},\"datePublished\":\"2021-02-18T07:13:33+00:00\",\"dateModified\":\"2021-02-18T07:13:36+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/\",\"url\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/\",\"name\":\"Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode\"}}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/#webpage\"},\"author\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#\/schema\/person\/5c3ea1c3869fc5aace6be92e60cb5daa\"},\"headline\":\"Disable Controls and Make Controls Read Only To Prevent Updating Altered Data in View Mode\",\"datePublished\":\"2021-02-18T07:13:33+00:00\",\"dateModified\":\"2021-02-18T07:13:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/#webpage\"},\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#organization\"},\"keywords\":\"mvvm\",\"articleSection\":\"Experiential\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tonghin.com.my\/blog\/2021\/02\/18\/disable-controls-and-make-controls-read-only-to-prevent-updating-altered-data-in-view-mode\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#\/schema\/person\/5c3ea1c3869fc5aace6be92e60cb5daa\",\"name\":\"Ng Ching Onn\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.tonghin.com.my\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5124ba2323631ad4d512f46bd9c04829?s=96&d=mm&r=g\",\"caption\":\"Ng Ching Onn\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/205"}],"collection":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/comments?post=205"}],"version-history":[{"count":5,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/205\/revisions"}],"predecessor-version":[{"id":210,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/posts\/205\/revisions\/210"}],"wp:attachment":[{"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/media?parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/categories?post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tonghin.com.my\/blog\/wp-json\/wp\/v2\/tags?post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}