title: Xamarin data binding how to bind the value times two
body: <p>I'm learning Xamarin Data Binding and learning the below code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               xmlns:local="clr-namespace:DataBinding"
               x:Class="DataBinding.MainPage"&gt;
      &lt;StackLayout&gt;
          &lt;Label x:Name="label" Text="twisting" FontSize="70" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"
                 BindingContext="{x:Reference Name=slider}"
                 Rotation="{Binding Path=Value}"&gt;
          &lt;/Label&gt;
          &lt;Slider x:Name="slider" BackgroundColor="Yellow" Maximum="360" VerticalOptions="CenterAndExpand"&gt;
          &lt;/Slider&gt;
      &lt;/StackLayout&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>I want to double the twisting speed so I modify the code:</p>
  
  <pre><code>&lt;Label x:Name="label" Text="twisting" FontSize="70" 
         HorizontalOptions="Center" VerticalOptions="CenterAndExpand"
         BindingContext="{x:Reference Name=slider}"
         Rotation="{Binding Path=Value*2}"&gt;
  &lt;/Label&gt;
  </code></pre>
  
  <p>But it doesn't work at all. I know the below solution works but I want a solution relating to the above:</p>
  
  <pre><code>&lt;Slider x:Name="slider" BackgroundColor="Yellow" Maximum="720" VerticalOptions="CenterAndExpand"&gt;
  &lt;/Slider&gt;
  </code></pre>
  
  <p>How to do it?</p>
  
  <p><strong>UPDATE1</strong></p>
  
  <p>I customize a converter as the below code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Globalization;
  using System.Text;
  using Xamarin.Forms;
  
  namespace DataBinding
  {
      public class MyValueConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
          {
              var speed = value as int?;
              return speed * 2;
          }
          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
          {
              return null;
          }
      }
  }
  </code></pre>
  
  <p>and modify the xaml as the below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               xmlns:local="clr-namespace:DataBinding"
               x:Class="DataBinding.MainPage"&gt;
      &lt;StackLayout&gt;
          &lt;Label x:Name="label" Text="twisting" FontSize="70" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"
                 BindingContext="{x:Reference Name=slider}"
                 Rotation="{Binding Path, Converter={StaticResource  myCo
  
      nverter}}"&gt;
              &lt;/Label&gt;
              &lt;Slider x:Name="slider" BackgroundColor="Yellow" Maximum="360" VerticalOptions="CenterAndExpand"&gt;
              &lt;/Slider&gt;
          &lt;/StackLayout&gt;
          &lt;ContentPage.Resources&gt;
              &lt;ResourceDictionary&gt;
                  &lt;local:MyValueConverter x:Key="myConverter"&gt;&lt;/local:MyValueConverter&gt;
              &lt;/ResourceDictionary&gt;
          &lt;/ContentPage.Resources&gt;
      &lt;/ContentPage&gt;
  </code></pre>
  
  <p>But my converter doesn't work properly and what is more, I made a breakpoint and found that the <code>Convert</code> function even not getting triggered.</p>
  
  <p><strong>UPDATE2</strong></p>
  
  <p>I found out the reason, the label in XAML should be the below:</p>
  
  <pre><code>&lt;Label x:Name="label" Text="twisting" FontSize="70" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"
                     BindingContext="{x:Reference Name=slider}"
                     Rotation="{Binding Path=Value, Converter={StaticResource  myConverter}}"&gt;
  &lt;/Label&gt;
  </code></pre>
  
  <p>and the type of value inside the Convert function is double instead of string:</p>
  
  <pre><code>public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
         var tmp = (Double)value*2;
         return tmp;
  }
  </code></pre>
  
  <p>Then it works.</p>