public static Storyboard FadeIn(this FrameworkElement frameworkElement, FrameworkElement parent, TimeSpan duration, Action completed = null) { if (parent == null) throw new NullReferenceException("parent"); if (BaseComponent.getCPtr(parent).Handle == IntPtr.Zero) throw new NullReferenceException("parent"); frameworkElement.Opacity = 0; string key = "Fade" + 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("Opacity")); animation.From = frameworkElement.Opacity; animation.To = 1; storyboard.Completed += (sender2, e2) => { parent.Resources.Remove(key); frameworkElement.Opacity = 1.0f; completed?.Invoke(); }; storyboard.Begin(); return storyboard; }