![](/img/trans.png)
[英]ContentFrame.Navigate works for navigation items but not AutoSuggestBox
[英]Proper way to add an AutoSuggestBox to Hamburger Navigation?
我刚刚开始学习UWP和xaml。 将AutoSuggestBox添加到“侧面导航”面板的正确方法是什么? (对不起,如果代码格式化错误,复制和粘贴效果不好)
我的Main.xaml具有我设置为Visible的AutoSuggestArea
</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>
在AutoSuggestArea的网格中,我定义了一个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="" 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>
我想要的基本上是与Windows上的Groove Music应用程序相同的行为,其中当导航视图关闭或最小化时,搜索栏消失。
相反,我得到这个
我假设您的意思是NavigationView
的NavigationPanel
。
这不是将AutoSuggestBox
放在NavigationView
。 NavigationView
具有NavigationView.AutoSuggestBox
属性。 您只需在此属性上设置一个AutoSuggestBox
,一切都会按预期进行。 像这样:
<NavigationView>
<NavigationView.AutoSuggestBox>
<AutoSuggestBox x:Name="NavViewSearchBox" QueryIcon="Find"/>
</NavigationView.AutoSuggestBox>
</NavigationVew>
您不必自己隐藏/显示此AutoSuggestBox
。 NavigationView
将自动为您执行此操作。 另外,您不必将AutoSuggestBox
放置在任何网格或任何内部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.