I have a UWP app with a NavigationView. I have been referring to this documentation which has working samples for everything except more in depth usage of the AutoSuggestBox. https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/navigationview
What I am trying to attempt is to update the ContentFrame of the MainPage NavigationView on a QuerySubmitted, I've attempted to do this with a ContentFrame.Navigate, however, this just ends up with the ContentFrame going completely blank. I am very confused as there is not much out there about AutoSuggestBox to go by that's relevant.
My current code looks like this:
private async void AutoSuggestBox_QuerySubmittedAsync(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
searchResultsClass.searchQuery = suggestBox.Text;
Debug.WriteLine(searchResultsClass.searchQuery);
await searchResultsClass.SearchAsync();
this.ContentFrame.Navigate(typeof(SearchResults));
}
SearchResults.xaml, which is identical to my other working views:
<Page
x:Class="TestApp.Views.SearchResults"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApp.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<GridViewHeaderItem Content="Search results for ''" FontSize="36"/>
</Grid>
</Page>
Cannot reproduce your issue on my side. ContentFrame.Navigate
can work well with QuerySubmitted
event handle. The AutoSuggestBox
is as follows in XAML:
<NavigationView.AutoSuggestBox>
<AutoSuggestBox x:Name="ASB" QueryIcon="Find" QuerySubmitted="ASB_QuerySubmitted"/>
</NavigationView.AutoSuggestBox>
And the result:
So that please add a break-point on this.ContentFrame.Navigate(typeof(SearchResults));
code line, and to debug your project to check if it can go through successfully to this step . If you still have issues please upload a minimal reproduced project.
Updated
For testing you project, the issue comes to be that the SearchResults
page lacks of the constructor method. For example:
public SearchResults()
{
this.InitializeComponent();
}
public async Task SearchAsync()
{
...
}
By default, each navigation creates a new instance of the specific Page (or subclass) requested, and disposes the previous page instance. Details please reference Page
class. So that create an instance SearchResults
in the MainPage
in your code snippet may make no sense and will not have influences with the showed navigated SearchResults
page.
If you want to pass the text of the AutoSuggestBox
to another page you should Pass information between pages by the navigate method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.