使用故事板调用动态创建的用户控件中的方法 [英] Use a storyboard to call a method in a usercontrol created dynamically

查看:25
本文介绍了使用故事板调用动态创建的用户控件中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使下面的内容更加清晰.我正在考虑使用计时器或 storyboard.CurrentTimeInvalidated 但故事板用于节拍器,时间以毫秒为单位:因此:

to add clarity to the below. I was considering using timers or storyboard.CurrentTimeInvalidated but the storyboard is for a metronome and the timings are in milliseconds: therefore:

从我在调试中看到的情况来看,CurrentTimeInvalidated 不会每毫秒引发一次事件,它似乎每 200 毫秒引发一次.

CurrentTimeInvalidated does not raise events every millisecond from what I have seen in debug, it seems to raise every 200ms.

定时器必须在代码中初始化,显然这与 storyboard.begin 顺序发生.结果,计时器在大约 30 秒的时间内无法对齐.

Timers have to be initialised in code and obviously this happens sequentially with the storyboard.begin. as a result the timers go out of alignment over a period of about 30 seconds.

我认为标题几乎概括了我想要做的事情,但是,很详细.

I think the title pretty much sums up what I want to do, but, in detail.

我有 8 个在运行时动态创建的用户控件.我有一个窗口,它在窗口的整个生命周期内运行故事板和动画(重复行为 = 永远和自动反转 = 真).

I have 8 user controls that are created dynamically at runtime. I have a window that is running a storyboard and animation throughout the lifetime of the window (repeat behaviour = forever and autoreverse = true).

我需要做的是在情节提要中按设定的时间间隔调用用户控件中的方法(按顺序).

what I need to do is at set intervals in the storyboard call a method in the usercontrols (in sequence).

是否可以绑定到故事板并创建一个调用用户控件方法的触发器?

is it possible to bind to the storyboard and create a trigger that calls a usercontrol method?

谢谢

丹.

推荐答案

首先,WPF 帧速率是 60 FPS,因此毫秒级 UI 更新是不可能的.如果你想进入每一帧的渲染,使用 CompositionTarget.Rendering 事件

Firstly, the WPF frame rate is 60 FPS so millisecond UI updates are not possible. If you want to tap into the rendering of each frame, use CompositionTarget.Rendering event

http://msdn.microsoft.com/en-us/library/system.windows.media.compositiontarget.rendering.aspx

这篇关于使用故事板调用动态创建的用户控件中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆