WP7 - 通过代码淡出用户控件,而不是 XAML
我正在尝试弹出一个用户控件,然后在 3 秒内将其淡出。我正在尝试使用以下代码,但在 Popup.LoadedEvent 和 Splash.LoadedEvent 的分配上我不断收到不正确的参数值。我做错了什么?
Splash s = new Splash();
DoubleAnimation fade = new DoubleAnimation()
{
Duration = new Duration(TimeSpan.FromMilliseconds(3000)),
From = 1.0,
To = 0.0,
RepeatBehavior = new RepeatBehavior(1)
};
fade.Completed += new EventHandler(fade_Completed);
this.popup = new Popup();
this.popup.Child = s;
EventTrigger et = new EventTrigger();
et.RoutedEvent = Popup.LoadedEvent;
Storyboard sb = new Storyboard();
sb.Children.Add(fade);
BeginStoryboard bs = new BeginStoryboard() { Storyboard = sb };
et.Actions.Add(bs);
this.popup.Triggers.Add(et);
this.popup.IsOpen = true;
我似乎也无法弄清楚在哪里/如何设置目标属性。
编辑:我能够使用提供的链接@Titan2782 获得答案。我已将其发布在下面的答案中。
I'm trying to popup a user control and then fade it out over 3 seconds. I'm trying to use the following code but I keep getting incorrect parameter value on the assignment of Popup.LoadedEvent as well as Splash.LoadedEvent. What am I doing wrong?
Splash s = new Splash();
DoubleAnimation fade = new DoubleAnimation()
{
Duration = new Duration(TimeSpan.FromMilliseconds(3000)),
From = 1.0,
To = 0.0,
RepeatBehavior = new RepeatBehavior(1)
};
fade.Completed += new EventHandler(fade_Completed);
this.popup = new Popup();
this.popup.Child = s;
EventTrigger et = new EventTrigger();
et.RoutedEvent = Popup.LoadedEvent;
Storyboard sb = new Storyboard();
sb.Children.Add(fade);
BeginStoryboard bs = new BeginStoryboard() { Storyboard = sb };
et.Actions.Add(bs);
this.popup.Triggers.Add(et);
this.popup.IsOpen = true;
I also cant seem to figure out where/how to set the target property.
Edit: I was able to get the answer using the link @Titan2782 provided. I've posted it in an answer below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 http://www.windowsphonegeek.com/articles/ wp7-transitions-in-deep--custom-transitions 它有一些代码可以与情节提要一起使用并设置目标属性。
check out http://www.windowsphonegeek.com/articles/wp7-transitions-in-depth--custom-transitions it has some code to work with storyboard and set the target properties.
您应该查看 Windows Phone 工具包中的过渡内容: http://blogs.msdn.com/b/wfaught/archive/2010/11/15/transitions.aspx
只需几行即可完成这些转换。
您可能会遇到一些问题,因为您使用弹出窗口,并且弹出窗口不存在于可视树中?
You should look into the transitions stuff in the windows phone toolkit: http://blogs.msdn.com/b/wfaught/archive/2010/11/15/transitions.aspx
its only a couple lines to get those transitions in.
You might have some issues here because you're using a popup, and the popup doesn't exist in the visual tree?
我有一个用 vb 编写的按钮的例子,应该不难翻译成 c#:
我想这也适用于弹出窗口。
I have an example with a button in vb, shouldn't be hard to translate into c#:
I suppose this works also with the Popup.
感谢@Titan2782 的回答,我终于弄清楚了
Thanks to @Titan2782 answer I was able to figure it out