[英]Horizontal Alignment AppBarButton - XAML
I need to alignment "Button1" on left, and "Button2" on right, in my CommandBar. 我需要在CommandBar中将左侧的“ Button1”和右侧的“ Button2”对齐。
I try put in code " HorizontalAlignment="Left" " in "Button1" but this not alignment in left. 我尝试在“ Button1”中放入代码“ HorizontalAlignment =“ Left”“,但是这在左侧没有对齐。 Always stay on right alignment. 始终保持正确对齐。
My code is: 我的代码是:
<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="" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="12,3,12,4"></TextBlock>
</Grid>
</AppBarButton.Content>
</AppBarButton>
<AppBarButton x:Name="Button2" Label="MyButton2">
<AppBarButton.Content>
<Button Content="" HorizontalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontSize="20" Width="32" Height="32" Padding="0" Background="Transparent"/>
</AppBarButton.Content>
</AppBarButton>
</CommandBar>
Someone Help me? 谁来帮帮我?
Thanks 谢谢
You should use PrimaryCommands
(to the right) and SecondaryCommands
(to the left) to move you appBarButton
s to the left or to the right and that should be based on Microsoft Guidelines 您应使用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="" 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="" HorizontalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontSize="20" Width="32" Height="32" Padding="0" Background="Transparent"/>
</AppBarButton.Content>
</AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
If you don't want to respect the guidelines you could simply use a Grid
inside an AppBar
instead, 如果您不想遵守这些准则,可以直接在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="" 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="" HorizontalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontSize="20" Width="32" Height="32" Padding="0" Background="Transparent"/>
</AppBarButton.Content>
</AppBarButton>
</Grid>
</AppBar>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.