将CommandBar(XAML)的内容居中

时间:2018-10-10 11:01:08

标签: c# xaml uwp

我希望能够将CommandBar的内容居中。我当前的代码是这个

<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>

这会将内容放在左侧,并在水平和垂直方向上对齐,但我需要在中央。

1 个答案:

答案 0 :(得分:0)

我已经在我的博客here上写过有关此内容的文章,因此请浏览全文。出现此问题的原因是在周年更新中添加的IsDynamicOverflowEnabled属性。设置为启用时,Grid的{​​{1}}所在的Content列位于CommandBar中,这意味着它仅为内容提供其实际需要并保留的空间Width="Auto"按钮的所有剩余空间。

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

CommandBar
相关问题