Search code examples
xamarinxamarin.formsxamarin.android

How do I create a Xamarin button with text AND a background image


From what I've read, a plain Xamarin button allows text but no background image. A Xamarin ImageButton allows for an image, but no text. So how can I get both without shelling out for a SyncFusion licence?


Solution

  • You can use grid to put text on ImageButton. You need to put Label and button same row.

    <Grid HorizontalOptions="Center"
      VerticalOptions="Center">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ImageButton HorizontalOptions="Center" VerticalOptions="Center"
            Source="Xamarin_logo.jpg"
                     Grid.Row="0"/>
          <Label HorizontalOptions="Center" VerticalOptions="Center"
         Text="button"
         TextColor="Purple"
                 FontSize="Large"
         Grid.Row="0"/>
    </Grid>