title: Why does my converter giving an invalid cast error?
body: <p>I created a Converter to convert from double to integer.</p>
  
  <p>But the line "return (int)value;" always gets a "specified cast is not valid."</p>
  
  <p>What do I have to do so that my Converter successfully converts a double and sends back an integer?</p>
  
  <p><strong>Converter:</strong></p>
  
  <pre><code>namespace TestChangeAngle
  {
      [ValueConversion(typeof(double), typeof(int))]
      class DoubleToIntegerConverter : IValueConverter
      {
          #region IValueConverter Members
  
          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              return (int)value;
          }
  
          public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              throw new NotImplementedException();
          }
  
          #endregion
      }
  }
  </code></pre>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Page x:Class="TestChangeAngle.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:TestChangeAngle"
      Title="Page1"&gt;
      &lt;Page.Resources&gt;
          &lt;local:DoubleToIntegerConverter x:Key="DoubleToIntegerConverter"/&gt;
      &lt;/Page.Resources&gt;
  
      &lt;StackPanel HorizontalAlignment="Left" Margin="20"&gt;
          &lt;Image Source="images\logo2.png" 
                 RenderTransformOrigin="0.5, 0.5"
                 Width="100" 
                 Margin="10"&gt;
              &lt;Image.RenderTransform&gt;
                  &lt;RotateTransform Angle="{Binding ElementName=TheSlider, Path=Value}"/&gt;
              &lt;/Image.RenderTransform&gt;
          &lt;/Image&gt;
          &lt;Slider x:Name="TheSlider"
                  Width="200" 
                  Minimum="0"
                  Maximum="360"
                  HorizontalAlignment="Center"
                  Margin="10" 
                  Cursor="Hand"/&gt;
          &lt;TextBox x:Name="TheAngle"
                   Margin="10"
                   Width="100"&gt;
              &lt;TextBox.Text&gt;
                  &lt;Binding ElementName="TheSlider"
                           Path="Value"
                           UpdateSourceTrigger="PropertyChanged"
                           Converter="{StaticResource DoubleToIntegerConverter}"
                           Mode="TwoWay"&gt;
                      &lt;Binding.ValidationRules&gt;
                          &lt;local:MinMaxValidationRule Minimum="0" Maximum="360"/&gt;
                      &lt;/Binding.ValidationRules&gt;
                  &lt;/Binding&gt;
              &lt;/TextBox.Text&gt;
          &lt;/TextBox&gt;
  
      &lt;/StackPanel&gt;
  &lt;/Page&gt;
  </code></pre>