fredrikm
Topic Author
Posts: 9
Joined: 17 Mar 2014, 15:47

[Unity] - ValueConverter and DoubleAnimation

23 Sep 2015, 15:17

I'm trying to do a simple storyboard where the animation "To" should use Binding towards a ContentControl.ActualHeight but with the value negated using a converter.
However I'm having trouble getting it to work.

I either get the below exception when using doubles
Exception: System.InvalidOperationException: Converter.Convert() expects Nullable`1 and Double is returned
at Noesis.Extend.ConverterConvert (IntPtr unityType, IntPtr cPtr, IntPtr valPtr, IntPtr typePtr, IntPtr paramPtr) [0x0006d]
Or when using float
Exception: '-0' (Boxed<Float32>) is not a valid value for property 'DoubleAnimation.To'
public class NegateDoubleConverter : IValueConverter
	{
		public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
		{
            double val = System.Convert.ToDouble(value);

            return -val;
		}
	
		public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException ();
		}
	}
      <Storyboard x:Key="OnTitleAreaInvisible">
       <DoubleAnimation Storyboard.TargetName="TitleArea"
        Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"
        From="0" To="{Binding ElementName=TitleArea, Path=ActualHeight, Converter={StaticResource negateDoubleConverter}}" Duration="0:0:0.5"/>
I'm probably doing something stupid but hoping someone here has an idea on how to solve this or can point me in the right direction?
 
User avatar
sfernandez
Site Admin
Posts: 3008
Joined: 22 Dec 2011, 19:20

Re: [Unity] - ValueConverter and DoubleAnimation

25 Sep 2015, 03:24

Hi,

There is a bug when using a Converter in the Binding and the target property is a Nullable type. We will fix it for the next release. Sorry for the inconvenience.

Apart from that, you should use float because as our API uses float instead of double: ActualWidth property is float, the DoubleAnimation animates float values, etc.

Who is online

Users browsing this forum: Ahrefs [Bot] and 11 guests