[Unity] - ValueConverter and DoubleAnimation
Posted: 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
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?
However I'm having trouble getting it to work.
I either get the below exception when using doubles
Or when using floatException: 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]
Exception: '-0' (Boxed<Float32>) is not a valid value for property 'DoubleAnimation.To'
Code: Select all
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 ();
}
}Code: Select all
<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"/>