2012-03-07 47 views
0

我是windows phone開發新手,我想知道WP7中是否有類似timedelay的東西。WP7中Popup的時間延遲

因爲我想在完全加載圖片幾秒後顯示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 

AFER加載圖片:

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 

回答

3

這是很容易,使用Timer類的任務(http://msdn.microsoft.com/ EN-US /庫/ 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。

+0

@ Torben-這是好的沒問題即使它在C#中也不需要抱歉,我可以管理。感謝實際上,現在我正在嘗試與後臺工作:) – coder 2012-03-07 10:27:01