2013-04-14 45 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

当然,提出了问题本身 –

相关问题