{"id":6612,"date":"2018-12-11T17:55:43","date_gmt":"2018-12-11T17:55:43","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=6612"},"modified":"2018-12-11T17:57:31","modified_gmt":"2018-12-11T17:57:31","slug":"ivalueconverter-convert-return-values","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/ivalueconverter-convert-return-values\/","title":{"rendered":"IValueConverter.Convert return values"},"content":{"rendered":"<p>I was updating some value converters in my converters GitHub repos. <a href=\"https:\/\/github.com\/putridparrot\/PutridParrot.Presentation.Converters\" rel=\"noopener\" target=\"_blank\">PutridParrot.Presentation.Converters<\/a> and realised I had been returning a null in situations where I really should have been returning DependencyProperty.UnsetValue.<\/p>\n<p>Generally we&#8217;ll either return a valid value from a converter or one of the following<\/p>\n<ul>\n<li>null<\/li>\n<li>DependencyProperty.UnsetValue<\/li>\n<li>Binding.DoNothing<\/li>\n<li>The original value<\/li>\n<\/ul>\n<p>The documentation (see References) states that when a <em>null<\/em> is returned then a &#8220;valid null value is used&#8221;. <\/p>\n<p>However we may actually prefer that the <em>FallbackValue<\/em> is used (if supplied) instead, hence we can return a <em>DependencyProperty.UnsetValue<\/em>. <\/p>\n<p>In cases where we neither want a value returned and do not want the <em>FallbackValue<\/em> to be called, then we return the <em>Binding.DoNothing<\/em>.<\/p>\n<p>Obviously, in situations where you do not know what to do with a binding value, it might be better to simply return the value passed into the Convert method. <\/p>\n<p><strong>References<\/strong><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.windows.data.ivalueconverter.convert?redirectedfrom=MSDN&#038;view=netframework-4.7.2#System_Windows_Data_IValueConverter_Convert_System_Object_System_Type_System_Object_System_Globalization_CultureInfo_\" rel=\"noopener\" target=\"_blank\">IValueConverter.Convert(Object, Type, Object, CultureInfo) Method<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was updating some value converters in my converters GitHub repos. PutridParrot.Presentation.Converters and realised I had been returning a null in situations where I really should have been returning DependencyProperty.UnsetValue. Generally we&#8217;ll either return a valid value from a converter or one of the following null DependencyProperty.UnsetValue Binding.DoNothing The original value The documentation (see References) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-6612","post","type-post","status-publish","format-standard","hentry","category-wpf"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=6612"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6612\/revisions"}],"predecessor-version":[{"id":6615,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6612\/revisions\/6615"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=6612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=6612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=6612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}