2013-04-14 73 views
2

我最近將搜索合同添加到了我的應用程序。它工作得很好!但是,只要我在應用程序中搜索時沒有運行,它只會以空白屏幕開始。我做了部分即使在OnSearchActivated方法中添加搜索結果。但即使我刪除了我添加的代碼,空白屏幕仍然存在。我創建了一個空白項目並將搜索合同添加到它。即使應用程序未運行,它仍在運行。這個問題似乎只與我的應用程序。我無法調試它,因爲它是應用程序甚至沒有運行時運行的東西。告訴我一個解決方案。在OnSearchActivatedWindows Store應用程序搜索合同空白屏幕

代碼和OnLaunched

Protected Overrides Async Sub OnSearchActivated(args As Windows.ApplicationModel.Activation.SearchActivatedEventArgs) 
    Dim previousContent As UIElement = Window.Current.Content 
    Dim frame As Frame = TryCast(previousContent, Frame) 
    If frame Is Nothing Then 
     frame = New Frame 
     Common.SuspensionManager.RegisterFrame(frame, "AppFrame") 
     If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then 
      Try 
       Await Common.SuspensionManager.RestoreAsync() 
      Catch ex As Common.SuspensionManagerException 
      End Try 
     End If 
    End If 
    frame.Navigate(GetType(SearchResultsPage1), args.QueryText) 
    Window.Current.Content = frame 
    Window.Current.Activate() 
End Sub 


Protected Overrides Async Sub OnLaunched(args As Windows.ApplicationModel.Activation.LaunchActivatedEventArgs) 
    AddHandler SearchPane.GetForCurrentView.SuggestionsRequested, AddressOf OnSearchPaneSuggestionsRequested 
'Contains definition of arrays ExNam, ExAbbr, ExInst, etc. removed from here to shorten the code and focus on its logic 
    If rootFrame Is Nothing Then 
     rootFrame = New Frame() 
     Train_Thy_Brain.Common.SuspensionManager.RegisterFrame(rootFrame, "appFrame") 
     If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then 
      Await Train_Thy_Brain.Common.SuspensionManager.RestoreAsync() 
     End If 
     Window.Current.Content = rootFrame 
    End If 
    If rootFrame.Content Is Nothing Then 
     If Not rootFrame.Navigate(GetType(Instructions), args.Arguments) Then 
      Throw New Exception("Failed to create initial page") 
     End If 
    End If 
    Window.Current.Activate() 
End Sub 

「同樣的命名空間定義在頂部這樣做,他們都沒有問題都不是。

回答

3

還有就是要調試你的應用程序的解決方案:在VS2012,您的項目在解決方案資源管理器單擊鼠標右鍵,然後去調試選項卡,在開始行動部分中,選中「不要啓動,但在啓動時調試我的代碼「。

現在您可以從搜索合同開始您的應用程序,即使它尚未運行並進行調試!

現在對於您的問題,我建議您在實際搜索某些內容之前檢查數據是否已加載。

+0

感謝您的快速回復。我猜的問題不是關於正在加載的數據。它甚至不顯示搜索界面。它顯示一個純粹的黑色屏幕。我認爲問題出在幀或頁面未加載。我沒有觸及OnSearchNavigated的代碼。所以,它至少應該顯示搜索頁面UI。 –

+0

非常感謝!!!!!你的建議調試這種方式對我有效(: –

0

您可能正在使用空查詢字符串進行搜索激活。檢查您的搜索激活處理程序,無論您是否處理空白查詢文本案例?

protected override void OnSearchActivated(SearchActivatedEventArgs args) 
{ 
    // your app initialization code here. 

    Frame frame = (Frame)Window.Current.Content; 
    if (!string.IsNullOrEmpty(args.QueryText)) 
    { 
     frame.Navigate(typeof(SearchResultsPage), args.QueryText); 
    } 
    else 
    { 
     // navigate to your app home page if the query text is empty. 
     frame.Navigate(typeof(Home), null); 
    } 

    Window.Current.Activate(); 
} 
+0

它似乎不是問題,謝謝反正,因爲即使通過空白查詢,它可以顯示搜索結果爲「」。問題是,沒有什麼是顯示在屏幕上,它是一個純黑色的屏幕 –

+0

很好的分享代碼,激活和onsearchactivated處理程序,在這種情況下 – Sushil

+0

當然,提出了問題本身 –

相關問題