我正在使用tutorial to build a media player in Silverlight并尝试将EventHandler
连接到timer.Tick
对象的DispatchTimer
事件,以便视频的时间为与Slider
对象同步。
示例代码在C#中,我不能在我的生活中找出VB.NET中使用RaiseEvent
和/或Handles
来连接事件的正确语法。以下是相关的C#代码。我将对我遇到的问题进行评论。
private DispatchTimer timer;
public Page()
{
//...
timer = new DispatchTimer();
timer.Interval = TimeSpan.FromMilliseconds(50);
timer.Tick += new EventHandler(timer_Tick); // <== I get stuck here b/c
// I can't do "timer.Tick += ..." in VB.NET
}
void timer_Tick(object sender, EventArgs e)
{
if (VideoElement.NaturalDuration.TimeSpan.TotalSeconds > 0)
{
sliderScrubber.Value = VideoElement.Position.TotalSeconds /
VideoElement.NaturalDuration.TimeSpan.TotalSeconds;
}
}
答案 0 :(得分:15)
像这样:
AddHandler timer.Tick, AddressOf timer_Tick
或者,
Private WithEvents timer as DispatcherTimer
Sub timer_Tick(sender As Object, e As EventArgs) Handles timer.Tick
End Sub