首页 > 解决方案 > 以 xamarin 形式格式化按钮文本和图像

问题描述

我想格式化文本和图像,就像附加的图像一样。如何使文本居中并将左侧带有一点填充的图像放在一边?

<Button StyleClass="btnFAF" Text="Field Activity" Image="icon.png" Grid.Row="0" Grid.Column="0" x:Name="btnFAF" Clicked="btnFAF_Clicked" BorderRadius="6">
    <Button.FontFamily>
        <OnPlatform x:TypeArguments="x:String">
            <On Platform="Android" Value="OpenSans-Regular.ttf#OpenSans-Regular"/>
        </OnPlatform>
    </Button.FontFamily>
</Button>

我想要的格式

标签: xamarinxamarin.forms

解决方案


而不是一个按钮,我只会使用一个布局控件来组成你想要的布局,并将一个 TapGestureRecognizer 附加到它上面

我将使用嵌套的 StackLayouts 进行说明,但这可能更适合使用 Grid 代替

<StackLayout Orientation="Horizontal" >
  <StackLayout.GestureRecognizers>
    <TapGestureRecognizer Tapped="MyTappedHandler" />
  <StackLayout.GestureRecognizers>
  <Image ... />
  <StackLayout>
    <Label ... />
    <Label ... />
  </StackLayout>
</StackLayout>

推荐阅读