<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>IValueConverter on David Marchbanks</title><link>https://davidmarchbanks.dev/en/tags/ivalueconverter/</link><description>Recent content in IValueConverter on David Marchbanks</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 23 Apr 2019 02:58:00 +0000</lastBuildDate><atom:link href="https://davidmarchbanks.dev/en/tags/ivalueconverter/index.xml" rel="self" type="application/rss+xml"/><item><title>Writing XAML Value Converters for Xamarin Forms</title><link>https://davidmarchbanks.dev/en/posts/writing-xaml-value-converters-for-xamarin-forms/</link><pubDate>Tue, 23 Apr 2019 02:58:00 +0000</pubDate><guid>https://davidmarchbanks.dev/en/posts/writing-xaml-value-converters-for-xamarin-forms/</guid><description>&lt;h2 id="explanation">Explanation&lt;/h2>
&lt;p>XAML isn&amp;rsquo;t perfect. It is often missing some tools that honestly should just be a party of the set. For example, express if a value is null or not null.&lt;/p>
&lt;p>What we will want to use is the IValueConverter interface. This interface has two methods defined:object Convert&lt;/p>
&lt;pre tabindex="0">&lt;code>object Convert(object value, Type targetType, object parameter, CultureInfo culture);&lt;/code>&lt;/pre>&lt;pre tabindex="0">&lt;code>object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);&lt;/code>&lt;/pre>&lt;p>These two methods are used to convert a value from one type to another. The first method is called to convert your base value. The second one is if you have two way binding, to convert it back. This is not always necessary unless you have a specific use case that can be converted from one value to another, such as Hex color to Color object and vice versa.&lt;/p></description></item></channel></rss>