Windows应用商店应用搜索合同空白屏幕

时间:2013-04-14 12:17:52

标签: vb.net windows-8 visual-studio-2012 windows-store-apps

我最近将搜索合同添加到了我的应用中。它工作得很棒!但是,每当我在应用程序中搜索它没有运行时,它只会以空白屏幕开始。即使在OnSearchActivated方法中,我也做了部分添加搜索结果。但即使我删除了我添加的代码,空白屏幕仍然存在。我创建了一个空白项目并将搜索合同添加到其中。即使应用程序没有运行,它也在使用它。问题似乎只与我的应用程序有关。我无法调试它,因为它是在应用程序甚至没有运行时运行的东西。告诉我一个解决方案。

OnSearchActivated和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

'命名空间定义也在顶部完成,因此它们不是问题。

2 个答案:

答案 0 :(得分:3)

有一个调试应用程序的解决方案:在VS2012中,右键单击解决方案资源管理器中的项目,然后转到调试选项卡并在< strong>开始操作部分,选中“ 不启动,但在启动时调试我的代码 ”。

现在您可以从搜索合同中启动您的应用,即使它尚未运行并进行调试!

现在针对您的问题,我建议您在实际搜索内容之前检查数据是否已加载。

答案 1 :(得分: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();
}