【问题标题】:Horizontal Alignment AppBarButton - XAML水平对齐 AppBarButton - XAML
【发布时间】:2015-12-09 13:21:16
【问题描述】:

我需要在我的 CommandBar 中对齐左侧的“Button1”和右侧的“Button2”。

我尝试在“Button1”中输入代码“Horizo​​ntalAlignment="Left"”,但这不是左对齐。始终保持正确对齐。

我的代码是:

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

有人帮帮我吗?

谢谢

【问题讨论】:

    标签: c# xaml alignment commandbar


    【解决方案1】:

    您应该使用PrimaryCommands(向右)和SecondaryCommands(向左)将appBarButtons 向左或向右移动,这应基于 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>
    

    如果您不想遵守这些准则,您可以简单地在 AppBar 中使用 Grid

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      • 2013-02-02
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多