<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>XAML on David Marchbanks</title><link>https://davidmarchbanks.dev/en/tags/xaml/</link><description>Recent content in XAML on David Marchbanks</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 23 May 2019 01:06:18 +0000</lastBuildDate><atom:link href="https://davidmarchbanks.dev/en/tags/xaml/index.xml" rel="self" type="application/rss+xml"/><item><title>Write your own Custom Controls for Xamarin.Forms</title><link>https://davidmarchbanks.dev/en/posts/write-your-own-custom-controls-for-xamarin-forms/</link><pubDate>Thu, 23 May 2019 01:06:18 +0000</pubDate><guid>https://davidmarchbanks.dev/en/posts/write-your-own-custom-controls-for-xamarin-forms/</guid><description>&lt;p>So why would you need to write a custom control for Xamarin? Does it have a purpose other than wrapping native controls that don&amp;rsquo;t exist in Xamarin? Why yes, it does serve a good purpose. I often will write a component to avoid having to copy and paste XAML repeatedly.&lt;/p>
&lt;h2 id="how-do-we-create-one">How do we create one?&lt;/h2>
&lt;p>I am going to assume you already have a project started in this post. I often create a directory/namespace called Controls in my PCL for this purpose. In any case, right click in your solution in Visual Studio&amp;rsquo;s PCL project and click Add, and then New Item.&lt;/p></description></item><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>