Sounds like you're looking for something like this:
public static T FadeIn<T>(this T uiElement, int durationInSeconds)
{
return uiElement.FadeFromTo(0, 1, durationInSeconds, false);
}
public static T FadeOut<T>(this T uiElement, int durationInSeconds)
{
return uiElement.FadeFromTo(1, 0, durationInSeconds, false);
}
public static T FadeFromTo<T>(this T uiElement,
double fromOpacity, double toOpacity,
int durationInSeconds, bool loopAnimation)
where T : UIElement
{
return (T)uiElement.wpfInvoke(()=>
{
var doubleAnimation =
new DoubleAnimation(fromOpacity, toOpacity,
new Duration(TimeSpan.FromSeconds(durationInSeconds)));
if(loopAnimation)
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
uiElement.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
return uiElement;
});
}
Ray Burns
2010-06-15 23:08:01