
{"id":644,"date":"2010-10-29T02:23:24","date_gmt":"2010-10-29T06:23:24","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=644"},"modified":"2010-10-29T02:23:24","modified_gmt":"2010-10-29T06:23:24","slug":"possible-wpf-bug-input-field-with-invalid-input-not-highlighted-on-startup","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=644","title":{"rendered":"Possible WPF Bug: Input Field with Invalid Input Not Highlighted On Startup"},"content":{"rendered":"<p>I am building a WPF demo, and I wanted to include validation. My scenario cannot be simpler: I show a form to create a shipment, and when you click &#8220;Save&#8221; button it checks the inputs and screams if something is wrong by marking appropriate fields with red. The application uses MVVM.<\/p>\n<p>Finding meaningful WPF examples for this scenario proved to be surprisingly hard.<\/p>\n<p>Apparently, WPF validation does not support this scenario easily. There is no easy way to say: hey, can you please run validation for the whole form now? One can probably look at INotifyDataErrorInfo, but I did not go that far.<\/p>\n<p>So, OK, I am fine with validating things as you go. But then if the form comes up with an empty value for &#8220;City&#8221; and this is invalid, the &#8220;City&#8221; field should be immediately highlighted as red, no?<\/p>\n<p>Well, it seems to work fine in .NET 4. In .NET 3.5 SP1, however, the value will become red only after the first change. Validation functions (IDataErrorInfo.Item[&#8220;City&#8221;]) gets called on form load, and I return &#8220;Please enter City&#8221;, but the validation framework seems to ignore it. If I just go ahead and hit &#8220;Save&#8221;, validation framework won&#8217;t report any errors.<\/p>\n<p>Occasionally, though, it may also work under .NET 3.5SP1, I have an app that seems to be working just fine. I built a simple repro case that works fine under .NET 4, but fails to validate under .NET 3.5SP1. I could not, however, build a reliable repro case that works under .NET 3.5SP1.<\/p>\n<p>This very simple thing &#8211; to validate a form on &#8220;GO&#8221;, proved to be too elusive, and I definitely don&#8217;t like enumerating my property names as strings in some indexer.<br \/>\n<a style=\"display:none\" href=\"http:\/\/www.codeproject.com\/script\/Articles\/BlogFeedList.aspx?amid=1181663\" rel=\"tag\">CodeProject<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am building a WPF demo, and I wanted to include validation. My scenario cannot be simpler: I show a form to create a shipment, and when you click &#8220;Save&#8221; <a href=\"https:\/\/ikriv.com\/blog\/?p=644\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4,12],"tags":[],"class_list":["entry","author-ikriv","post-644","post","type-post","status-publish","format-standard","category-hack","category-wpf"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=644"}],"version-history":[{"count":0,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/644\/revisions"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}