Proper way to add an AutoSuggestBox to Hamburger Navigation?

349 Views Asked by At

I'm just starting to learn UWP and xaml. What is the proper way to add a AutoSuggestBox to the Side Navigation panel? (Sorry for the bad code formatting in advance, copy and paste wasn't great)

My Main.xaml has an AutoSuggestArea that I have set to Visible

</VisualStateGroup>
  <VisualStateGroup x:Name="AutoSuggestGroup">
    <VisualState x:Name="AutoSuggestBoxVisible"/>
    <VisualState x:Name="AutoSuggestBoxCollapsed">
  <VisualState.Setters>
    <Setter Target="AutoSuggestArea.Visibility" Value="Visible"/>
  </VisualState.Setters>
</VisualState>
</VisualStateGroup>

and in the Grid for the AutoSuggestArea I have defined an AutoSuggestBox

<Grid x:Name="AutoSuggestArea" Height="44" Grid.Row="3" VerticalAlignment="Center">

<ContentControl x:Name="PaneAutoSuggestBoxPresenter" Content="{TemplateBinding AutoSuggestBox}" HorizontalContentAlignment="Stretch" IsTabStop="False" Margin="16,0,16,0" VerticalContentAlignment="Center"/>

<Button x:Name="PaneAutoSuggestButton" Content="&#xE11A;" MinHeight="44" Style="{TemplateBinding PaneToggleButtonStyle}" Visibility="Collapsed" Width="{TemplateBinding CompactPaneLength}"/>

    <AutoSuggestBox Width="234" VerticalAlignment="Center" 
       HorizontalAlignment="Center"
       PlaceholderText="Search" Name ="boxS"                            
       QuerySubmitted="AutoSuggestBox_QuerySubmitted" 
       TextChanged="AutoSuggestBox_TextChanged">
        <AutoSuggestBox.TextBoxStyle>
          <Style TargetType="TextBox">
          <Setter Property="IsHandwritingViewEnabled" Value="False"/>
          <Setter Property="BorderThickness" Value="0"/>
        </Style>
      </AutoSuggestBox.TextBoxStyle>
        <AutoSuggestBox.QueryIcon>
          <SymbolIcon Symbol="Find" Foreground="Black">                                                   
             <SymbolIcon.RenderTransform>
             <CompositeTransform ScaleX="1" ScaleY="1"/>                                         
             </SymbolIcon.RenderTransform>
          </SymbolIcon>
       </AutoSuggestBox.QueryIcon>
    </AutoSuggestBox>
</Grid>

What I want is basically Identical Behaviour as the Groove Music app on Windows, where the Search bar disappears as the Nav View is closed or Minimized.

Instead I get this

1

There are 1 best solutions below

0
On

I am assuming you meant NavigationView by NavigationPanel.

This is not how you put an AutoSuggestBox in NavigationView. NavigationView has an NavigationView.AutoSuggestBox property. You just set an AutoSuggestBox on this property, and every thing will work as expected. Like this:

<NavigationView>
    <NavigationView.AutoSuggestBox>
        <AutoSuggestBox x:Name="NavViewSearchBox" QueryIcon="Find"/>
    </NavigationView.AutoSuggestBox>
</NavigationVew>

You don't have to hide/show this AutoSuggestBox yourself. NavigationView will automatically do this for you. Also, you don't have to put thie AutoSuggestBox inside any grid or anything.