I am trying to fade a text box within specified time. This code works on Windows Phone but it doesn't work in a Windows 8 application. I made changes to fix as many errors as possible. but I couldn't resolve one of them: cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<object>"
arises on the expression sb.Completed += ehl
. The full function is below:
public static void Fade(UIElement target, double ValueFrom, double ValueTo, double Duration)
{
DoubleAnimation da = new DoubleAnimation();
da.From = ValueFrom;
da.To = ValueTo;
da.Duration = TimeSpan.FromSeconds(Duration);
da.AutoReverse = false;
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(da, "opacity");
Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(da, target);
Windows.UI.Xaml.Media.Animation.Storyboard sb = new Windows.UI.Xaml.Media.Animation.Storyboard();
sb.Children.Add(da);
EventHandler ehl = null;
ehl = (s, args) =>
{
sb.Stop();
sb.Completed+= ehl; //error occurs here
target.Opacity = ValueTo;
};
sb.Completed += ehl; //error occurs here
sb.Begin();
}