How to horizontally align AppBarButton in command bar

前端 未结 3 717
慢半拍i
慢半拍i 2021-02-06 00:54

I want to align my single AppBarButton to the right on a CommandBar in a Page.BottomBar?

In design it shows the app bar but

相关标签:
3条回答
  • 2021-02-06 01:29

    HorizontalAlignment doesn't work. This is a work around that we use:

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

    And it simply works:

    Cheers :P

    0 讨论(0)
  • 2021-02-06 01:43

    You cannot center buttons in a CommandBar. Having said that, if you need this type of control you simply need to switch to the AppBar control instead. Same behavior, just more flexibility. The trade-off is that this control is not universal and will not render in Phone. You would need to reveal a CommandBar for your Phone platform head.

    0 讨论(0)
  • This works for me getting a left justified back button. It is courtesy of Rudy Huyn's blog at: 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>
    

    Rudy has some theories about why Microsoft made it this way. Content on the left everything else on the right.

    By the way, that IsCompact="True" is very important or you get annoying labels as well as icons.

    Cheers Tim

    0 讨论(0)
提交回复
热议问题