如何在命令栏中水平对齐AppBarButton

时间:2014-08-26 12:48:26

标签: xaml winrt-xaml windows-phone-8.1 win-universal-app

我想将AppBarButton中的单CommandBar对齐Page.BottomBar中的app bar button

在设计中它显示右侧的AppBarButton,但在模拟器中,按钮始终位于中心?

有没有办法在page bottom bar中对齐<Page.BottomAppBar> <CommandBar HorizontalAlignment="Right" HorizontalContentAlignment="Right"> <CommandBar.PrimaryCommands> <AppBarButton Margin="100,0,0,0" HorizontalAlignment="Right" HorizontalContentAlignment="Right" IsEnabled="True" Name="btnNext" Icon="Next" x:Uid="AppBarNext" Label="Next1"></AppBarButton> </CommandBar.PrimaryCommands> </CommandBar> </Page.BottomAppBar>

修改

{{1}}

3 个答案:

答案 0 :(得分:8)

HorizontalAlignment不起作用。这是我们使用的一种解决方法:

<Page.BottomAppBar>
    <AppBar IsSticky="true">
        <Grid Margin="8,8,8,8">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <AppBarButton Grid.Column="0" 
                          x:Name="SelectButton" Icon="Bullets"
                          Label="!Select"  />
            <AppBarButton Grid.Column="1" 
                          x:Name="SelectAllButton" 
                          Icon="SelectAll" 
                          Label="!Select All"/>
            <AppBarButton Grid.Column="3" 
                          x:Name="DetailsButton" 
                          Icon="Edit"
                          Label="!Details"/>
        </Grid>
    </AppBar>
</Page.BottomAppBar>

它只是起作用:

enter image description here

干杯:P

答案 1 :(得分:7)

您无法将按钮置于CommandBar中心。话虽如此,如果你需要这种类型的控件,你只需要切换到AppBar控件。相同的行为,更灵活。权衡是这种控制不是通用的,不会在电话中呈现。您需要为您的手机平台头显示一个CommandBar。

答案 2 :(得分:2)

这对我来说是一个左对齐的后退按钮。这是由Rudy Huyn的博客提供的:Display an AppBarButton on the left

<Page.TopAppBar>
    <CommandBar>
        <CommandBar.Content>
            <AppBarButton x:Name="Back" Icon="Back" Label="Back" Click="Back_Click" IsCompact="True"/>
        </CommandBar.Content>

        <AppBarButton x:Name="videoButton" Icon="Video" Label="Video"/>
    </CommandBar>
</Page.TopAppBar>
鲁迪有一些关于为什么微软这样做的理论。左边的内容是右边的其他内容。

顺便说一下,IsCompact =“True”非常重要,否则你会看到烦人的标签和图标。

干杯蒂姆