Горизонтальное выравнивание AppBarButton — XAML

Мне нужно выровнять «Button1» слева и «Button2» справа в моем CommandBar.

Я пытаюсь вставить код HorizontalAlignment="Left" в "Button1", но это не выравнивание по левому краю. Всегда оставайтесь на правильном выравнивании.

Мой код:

 <CommandBar x:Name="CommandBarTest" Grid.Row="1">
            <AppBarButton x:Name="Button1" Label="MyButton1" Click="MyButton1_Click" HorizontalAlignment="Left">
                <AppBarButton.Content>
                    <Grid>
                        <Border Margin="4,-1,0,13" Canvas.ZIndex="1" CornerRadius="15" Background="Black" Height="19" Width="19" HorizontalAlignment="Left">
                            <TextBlock Text="2" FontFamily="Segoe UI" FontSize="12" Foreground="White" TextLineBounds="Tight" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="3,5"></TextBlock>
                        </Border>
                        <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="24" Text="&#xE7EE;" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="12,3,12,4"></TextBlock>
                    </Grid>
                </AppBarButton.Content>
            </AppBarButton>
            <AppBarButton x:Name="Button2" Label="MyButton2">
                <AppBarButton.Content>
                    <Button Content="&#xE840;" HorizontalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontSize="20" Width="32" Height="32" Padding="0" Background="Transparent"/>
                </AppBarButton.Content>
            </AppBarButton>
 </CommandBar>

Кто-нибудь Помогите мне?

Спасибо


person fipcurren88    schedule 13.09.2015    source источник


Ответы (1)


Вы должны использовать PrimaryCommands (вправо) и SecondaryCommands (влево), чтобы переместить appBarButton влево или вправо, и это должно быть основано на рекомендациях Microsoft.

 <CommandBar x:Name="CommandBarTest" Grid.Row="1" >
        <CommandBar.SecondaryCommands>
            <AppBarButton  x:Name="Button1" Label="MyButton1">
                <AppBarButton.Content>
                    <Grid>
                        <Border Margin="4,-1,0,13" Canvas.ZIndex="1" CornerRadius="15" Background="Black" Height="19" Width="19" HorizontalAlignment="Left">
                            <TextBlock Text="2" FontFamily="Segoe UI" FontSize="12" Foreground="White" TextLineBounds="Tight" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="3,5"></TextBlock>
                        </Border>
                        <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="24" Text="&#xE7EE;" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="12,3,12,4"></TextBlock>
                    </Grid>
                </AppBarButton.Content>
            </AppBarButton>
        </CommandBar.SecondaryCommands>   
        <CommandBar.PrimaryCommands>
            <AppBarButton x:Name="Button2" Label="MyButton2">
                <AppBarButton.Content>
                    <Button Content="&#xE840;" HorizontalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontSize="20" Width="32" Height="32" Padding="0" Background="Transparent"/>
                </AppBarButton.Content>
            </AppBarButton>
        </CommandBar.PrimaryCommands>           
    </CommandBar>

Если вы не хотите соблюдать рекомендации, вы можете просто использовать вместо них Grid внутри AppBar,

 <AppBar>
        <Grid x:Name="CommandBarTest" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>

            <AppBarButton Grid.Column="0"  x:Name="Button1" Label="MyButton1">
                <AppBarButton.Content>
                    <Grid>
                        <Border Margin="4,-1,0,13" Canvas.ZIndex="1" CornerRadius="15" Background="Black" Height="19" Width="19" HorizontalAlignment="Left">
                            <TextBlock Text="2" FontFamily="Segoe UI" FontSize="12" Foreground="White" TextLineBounds="Tight" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="3,5"></TextBlock>
                        </Border>
                        <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="24" Text="&#xE7EE;" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="12,3,12,4"></TextBlock>
                    </Grid>
                </AppBarButton.Content>
            </AppBarButton>


            <AppBarButton x:Name="Button2" Grid.Column="2" Label="MyButton2">
                <AppBarButton.Content>
                    <Button Content="&#xE840;" HorizontalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontSize="20" Width="32" Height="32" Padding="0" Background="Transparent"/>
                </AppBarButton.Content>
            </AppBarButton>
        </Grid>
    </AppBar>
person SamTh3D3v    schedule 13.09.2015