WP7中弹出窗口的时间延迟

时间:2012-03-07 09:56:25

标签: windows-phone-7 popup timedelay

我是Windows手机开发的新手,我想知道WP7中是否有像timedelay这样的东西。

因为我想在完全加载图像后几秒钟显示Popup(比如在5秒之后我需要自动打开一个弹出窗口)而不点击任何按钮。

截至目前,我正在这样做,但只要图像加载就会打开Popup。

 Public Sub New()
    InitializeComponent()
    photoChooserTask = New PhotoChooserTask()
    AddHandler photoChooserTask.Completed, AddressOf photoChooserTask_Completed
 End Sub
 Dim photoChooserTask As PhotoChooserTask

添加图片:

 Private Sub AddImage_Click(sender As System.Object, e As System.EventArgs)
        Try
            photoChooserTask.Show()

        Catch ex As System.InvalidOperationException

            MessageBox.Show("An error occurred.")
    End Try
 End Sub

载入图片:

 Private Sub photoChooserTask_Completed(sender As Object, e As PhotoResult)

        If e.TaskResult = TaskResult.OK Then
            'Code to display the photo on the page in an image control named myImage.
            Dim bmp As System.Windows.Media.Imaging.BitmapImage = New System.Windows.Media.Imaging.BitmapImage()
            bmp.SetSource(e.ChosenPhoto)
            myImage.Source = bmp
        End If

  Dim popup As New Popup()
        popup.VerticalOffset = 140
        Dim control As New PhonePage3()
        popup.Child = control
        popup.IsOpen = True
    End Sub
  End Sub

1 个答案:

答案 0 :(得分:3)

这很简单,使用Timer类来完成任务(http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx)。

创建计时器:

Timer myTimer = new Timer(OnTimerDone);

启动计时器以在5秒(5000毫秒)内获得回调:

myTimer.Change(5000, Timeout.Infinite);

定义回调函数:

private void OnTimerDone(object state)
{
    // your code here
}

这就是全部:-)抱歉C#代码,但我认为将其翻译成VB应该很容易。