2
votes

Is it possible to put a stacklayout in a button?

      <StackLayout HorizontalOptions="Start" Orientation="Horizontal">
             <Label Text="s" FontFamily="icon-font" FontSize="16" FontAttributes="Bold" TextColor="{StaticResource orangeColor}"></Label>
             <Label Text="Test" FontSize="16" FontAttributes="Bold" />
      </StackLayout>

I have a icon font file. I want to render the icon and the normal text inside of the button content. Is it possible to do in Xamarin Forms?

1
No, but you can make your StackLayout look and act like a button. - Jason

1 Answers

2
votes

You can add a TapGestureRecognizer to your labels so you can "click" them like a Button

var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) => {
   // handle the tap
};
myLabel.GestureRecognizers.Add(tapGestureRecognizer);