Silverlight 4.0 如何为任何控件设置模糊效果的动画?
我想要一个可重用的函数,它只对任何特定的有效控件类型产生模糊效果 e、 g 我不确定如何在代码隐藏中动态创建动画来实现这一点。演示了如何在代码中定义动画和故事板 您需要添加BlurEffect并使用BlurEffect,而不是RotateTransform.Angle属性,如下所示:Silverlight 4.0 如何为任何控件设置模糊效果的动画?,silverlight-4.0,effects,Silverlight 4.0,Effects,我想要一个可重用的函数,它只对任何特定的有效控件类型产生模糊效果 e、 g 我不确定如何在代码隐藏中动态创建动画来实现这一点。演示了如何在代码中定义动画和故事板 您需要添加BlurEffect并使用BlurEffect,而不是RotateTransform.Angle属性,如下所示: control.Effect.BeginAnimation(Blureffect.RadiusProperty, animation); -编辑- 现在我知道您使用的是Silverlight,而不是wpf(whe
control.Effect.BeginAnimation(Blureffect.RadiusProperty, animation);
-编辑-
现在我知道您使用的是Silverlight,而不是wpf(where)
我会设法找到silverlight的解决方案
-编辑2-
你看过/试过吗?Msdn还有一个
-编辑3-
你的指导使我找到了正确的答案,答案如下:
private void BlurSomething(FrameworkElement control)
{
var storyboard = new Storyboard();
var animation = new DoubleAnimation
{
From = 0,
To = 8,
Duration = new TimeSpan(0, 0, 0, 1, 0),
AutoReverse = true
};
var effect = new BlurEffect();
control.Effect = effect;
storyboard.Children.Add(animation);
Storyboard.SetTarget(storyboard, control.Effect);
Storyboard.SetTargetProperty(storyboard, new PropertyPath("Radius"));
storyboard.Begin();
}
需要注意的是,Silverlight并不像WPF那样容易制作动画,但最终这是可以做到的。我认为你根本不想让xaml知道模糊,对吗?如果你是这个意思,我不想在xaml中这样做。但是你也不想在xaml中定义模糊效果,对吗?如果这是你要问的,我不介意它作为一种资源。无论如何,我都会在代码中触发这个。我已经更新了我的代码示例,以显示除我无法理解的内容之外的所有内容。是的,我看到了,但它并没有涵盖如何在BlurEffect上对半径进行双重动画。你可以用与文章中相同的方法进行操作,只需将RotateTransform.AngleProperty切换到BlurEffect.RadiusProperty对不起,无法仅切换这些,因为BlurEffect没有BeginAnimation。啊。。。你用的是silverlight,不是wpf。。对不起,我离你很近了。将使用最终解决方案更新您的答复。
private void BlurSomething(FrameworkElement control)
{
var storyboard = new Storyboard();
var animation = new DoubleAnimation
{
From = 0,
To = 8,
Duration = new TimeSpan(0, 0, 0, 1, 0),
AutoReverse = true
};
var effect = new BlurEffect();
control.Effect = effect;
storyboard.Children.Add(animation);
Storyboard.SetTarget(storyboard, control.Effect);
Storyboard.SetTargetProperty(storyboard, new PropertyPath("Radius"));
storyboard.Begin();
}