Feldruebe
Topic Author
Posts: 20
Joined: 24 Jun 2018, 11:52

Animating DependencyProperty

11 Feb 2020, 23:02

Hello,

i am running into an error when i try to animate a dependency property.
I want to expose predefined render transforms to the user of the control through dependency properties.
The user can then define a storyboard to animate this properties.

In the code behind i have something like this:
public static readonly DependencyProperty ScaleXProperty = DependencyProperty.Register(
            "ScaleX", typeof(double), typeof(AnimatedTextBlock), new PropertyMetadata(1d));
            
 public double ScaleX
 {
            get { return (double)GetValue(ScaleXProperty); }
            set { SetValue(ScaleXProperty, value); }
 }            
 
The storyboard looks like this:
<Storyboard x:Key="Storyboard"> 
                <DoubleAnimation Storyboard.TargetProperty="(controls1:AnimatedTextBlock.ScaleX)"
                                                  From="2" To="1" Duration="0:0:0.5"/>
</Storyboard> 
In Unity i get the following errors:

[noesis] Can't animate 'Double' value with a DoubleAnimation
UnityEngine.Debug:LogError(Object)
NoesisUnity:UnityLog(Int32, String) (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:116)
Noesis.View:Noesis_View_Update(HandleRef, Double)
Noesis.View:Update(Double) (at Assets/NoesisGUI/Plugins/API/Core/View.cs:271)
NoesisView:LateUpdate() (at Assets/NoesisGUI/Plugins/NoesisView.cs:822)

[noesis] Can't animate property 'NoesisGui.Assets.Scripts.GuiUtility.Controls.AnimatedTextBlock.ScaleX' with a DoubleAnimation
UnityEngine.Debug:LogError(Object)
NoesisUnity:UnityLog(Int32, String) (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:116)
Noesis.View:Noesis_View_Update(HandleRef, Double)
Noesis.View:Update(Double) (at Assets/NoesisGUI/Plugins/API/Core/View.cs:271)
NoesisView:LateUpdate() (at Assets/NoesisGUI/Plugins/NoesisView.cs:822)

Am i doing something wrong or do i miss something?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Animating DependencyProperty

16 Feb 2020, 18:47

That error is happening because in Noesis our API uses floats and to be compatible with WPF we made the DoubleAnimation/DoubleAnimationUsingKeyFrames to animate float values.

If you change your properties to be float the animation should work fine.
public static readonly DependencyProperty ScaleXProperty = DependencyProperty.Register(
  "ScaleX", typeof(float), typeof(AnimatedTextBlock), new PropertyMetadata(1.0f));
            
public float ScaleX
{
  get { return (float)GetValue(ScaleXProperty); }
  set { SetValue(ScaleXProperty, value); }
} 
 
Feldruebe
Topic Author
Posts: 20
Joined: 24 Jun 2018, 11:52

Re: Animating DependencyProperty

17 Feb 2020, 16:06

Thanks for the Answer. I will keep that in mind.

I worked around the problem by exposing the whole transforms (ScaleTransform, RotateTransform,...) as DependencyProperties.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Animating DependencyProperty

21 Feb 2020, 18:07

Thanks a lot for your feedback!

Who is online

Users browsing this forum: Google [Bot], vinick and 58 guests