User avatar
stonstad
Topic Author
Posts: 241
Joined: 06 Jun 2016, 18:14
Location: Lesser Magellanic Cloud
Contact:

Programmatic Storyboard Creation

18 Oct 2023, 16:47

I'm getting this warning, but I am not sure what it means.
[NOESIS/W] Can't Stop Storyboard, it was initiated with a different Target
UnityEngine.Debug:LogWarning (object,UnityEngine.Object)
NoesisUnity:UnityLog (int,string) (at D:/Source/StellarConquest/StellarConquest.Utilities/Noesis/3.2.1/Runtime/NoesisUnity.cs:355)
Noesis.Storyboard:Stop () (at D:/Source/StellarConquest/StellarConquest.Utilities/Noesis/3.2.1/Runtime/API/Proxies/Storyboard.cs:193
I tried making the storyboard controllable via the overload, but the warning persists. Is there something I can do to avoid creating this wanring?
public static Storyboard ResizeHeight(this FrameworkElement frameworkElement, FrameworkElement parent, float height, TimeSpan duration, Action completed = null)
{
            if (parent == null)
                throw new NullReferenceException("parent");
            if (BaseComponent.getCPtr(parent).Handle == IntPtr.Zero)
                throw new NullReferenceException("parent");

            string key = "Resize" + frameworkElement.GetHashCode();
            StopStoryboard(key, parent);

            if (parent.Resources.Contains(key))
            {
                UnityEngine.Debug.LogWarning("Resource already exists");
                return null;
            }

            DoubleAnimation animation = new DoubleAnimation();
            animation.Duration = new Duration(duration);
            animation.AutoReverse = false;
            animation.FillBehavior = FillBehavior.Stop;

            Storyboard storyboard = new Storyboard();
            storyboard.AutoReverse = false;
            storyboard.Duration = animation.Duration;
            storyboard.FillBehavior = FillBehavior.Stop;
            storyboard.Children.Add(animation);

            parent.Resources.Add(key, storyboard);

                Storyboard.SetTarget(animation, frameworkElement);
                Storyboard.SetTargetProperty(animation, new PropertyPath("Height"));
                animation.From = frameworkElement.Height;
                animation.To = height.Value;
                storyboard.Completed += (sender2, e2) =>
                {
                    parent.Resources.Remove(key);
                    frameworkElement.Height = height.Value;
                    completed?.Invoke();
                };

            storyboard.Begin();
            return storyboard;
 }
 
User avatar
nadjibus
Posts: 33
Joined: 24 Feb 2022, 04:09

Re: Programmatic Storyboard Creation

18 Oct 2023, 20:42

I think you should call the other "Begin" method overload that accepts a FrameworkElement
 storyboard.Begin(frameworkElement);
Happy to a find a familiar Unity Forums user here! Not lot of Unity devs use Noesis, I presume you're coming from a WPF/Silverlight background?
 
User avatar
stonstad
Topic Author
Posts: 241
Joined: 06 Jun 2016, 18:14
Location: Lesser Magellanic Cloud
Contact:

Re: Programmatic Storyboard Creation

19 Oct 2023, 20:47

Thank you - that was the cause!

Yes, I have a background in WPF and Silverlight. I'm comfortable with many UI frameworks (HTML/CSS, Swing, QT, Windows Forms, WPF...). Noesis is just terrific and their investment in the quality of the product really shows.
 
User avatar
nadjibus
Posts: 33
Joined: 24 Feb 2022, 04:09

Re: Programmatic Storyboard Creation

21 Oct 2023, 13:55

Yes it's awesome! when I found Noesis the first time, I couldn't believe my eyes! being able to transfer my long experience in WPF/Silverlight/Xamarin.Forms to Unity (and avoid using its awful UI system as a bonus) is like being in heaven.
 
User avatar
sfernandez
Site Admin
Posts: 3013
Joined: 22 Dec 2011, 19:20

Re: Programmatic Storyboard Creation

24 Oct 2023, 19:42

Thanks for the kind words :)

Who is online

Users browsing this forum: No registered users and 5 guests