首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在SearchBox中显示CommandBar

如何在SearchBox中显示CommandBar
EN

Stack Overflow用户
提问于 2017-05-11 06:46:14
回答 1查看 1.3K关注 0票数 4

我想在AutoSuggestBox中添加一个CommandBar。但是,下面的代码并不会使AutoSuggestBox扩展。我试着设置HorizontalContentAlignment="Stretch"HorizontalAlignment="Stretch",但没有影响。我遗漏了什么?

代码语言:javascript
复制
    <CommandBar Grid.Row="0" HorizontalContentAlignment="Stretch">
        <CommandBar.Content>
            <AutoSuggestBox HorizontalAlignment="Stretch" Margin="8 8 8 4" PlaceholderText="Search podcasts" QueryIcon="Find">
                <Interactivity:Interaction.Behaviors>
                    <Core:EventTriggerBehavior EventName="QuerySubmitted">
                        <Core:InvokeCommandAction                         
                    Command="{Binding SearchCommand}"
                    InputConverter="{StaticResource QueryArgsConverter}" />
                    </Core:EventTriggerBehavior>
                </Interactivity:Interaction.Behaviors>
            </AutoSuggestBox>
        </CommandBar.Content>
    </CommandBar>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-12 09:46:44

我试着设置HorizontalContentAlignment=“拉伸”和HorizontalAlignment=“拉伸”,但没有影响。

Horizontal​Alignment设置为stretch意味着扩展元素以填充父元素的整个布局槽。在您的代码片段中,AutoSuggestBox位于CommandBar的内容中,如果我们使用Content​Control检查CommandBar的内容,则会检查CommandBar的内容。因此,实际上父元素是一个ContentControl,而不是直接的CommandBar。这里的ContentControl大小似乎取决于它的子大小,因此AutoSuggestBox没有需要填充的空间。

实际上,内容区域是设计成与条形图的左边对齐的。详细资料见应用程序栏的解剖。所以我不建议你把它伸开。您可以考虑使用其他控件作为AutoSuggestBox的容器。如果您确实希望具有拉伸效果,您可以手动计算AutoSuggestBox的宽度。例如:

代码语言:javascript
复制
<CommandBar x:Name="cmdbar">
    <CommandBar.Content>
        <AutoSuggestBox
            x:Name="autobox"
            Width="{Binding ElementName=cmdbar, Path=ActualWidth}"
            HorizontalAlignment="Stretch"
            PlaceholderText="Search podcasts"
            QueryIcon="Find" />
    </CommandBar.Content>
</CommandBar>
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43908315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档