首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以CommandBar (XAML)内容为中心

以CommandBar (XAML)内容为中心
EN

Stack Overflow用户
提问于 2018-10-10 11:01:07
回答 1查看 287关注 0票数 2

我希望能够集中我的CommandBar的内容。我现在的代码是

代码语言:javascript
复制
<Page.BottomAppBar>
    <CommandBar x:Name="BottomBar"  Background="Black" Visibility="Collapsed" OverflowButtonVisibility="Collapsed" >

        <CommandBar.PrimaryCommands>
            <AppBarButton Name="btnSend" Icon="Forward"  Foreground="White"/>
            <AppBarButton Name="btnCancel" Icon="Clear"  Foreground="White"/>
        </CommandBar.PrimaryCommands>

        <CommandBar.Content>
            <TextBlock Name="tbBar" Text="EOOOOOOOOO" Foreground="White" Margin="12,14" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </CommandBar.Content>
    </CommandBar>

</Page.BottomAppBar>

这把内容放在左边,水平和垂直对齐,但我需要它在中间。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-10 12:00:01

我已经在我的博客这里上写过这件事,所以请浏览它以获得完整的细节。造成此问题的原因是“周年更新”中添加的IsDynamicOverflowEnabled属性。当设置为enabled时,GridContent of CommandBar驻留在set Width="Auto"中,这意味着它只给内容它实际需要的空间,并将所有剩余的空间保留给CommandBar按钮。

最简单的解决方案是将IsDynamicOverflowEnabled设置为false。如果要保留此特性,则必须修改CommandBar的默认模板。

代码语言:javascript
复制
<CommandBar HorizontalContentAlignment="Center"
            IsDynamicOverflowEnabled="False">
   <CommandBar.Content>
      <TextBlock Text="Content" />
   </CommandBar.Content>
</CommandBar>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52738730

复制
相关文章

相似问题

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