Creating a Button with Multiple Components

Nathan Sokalski 4,106 Reputation points
2020-11-24T17:25:33.027+00:00

I want to create a Button that is made up of multiple parts. I am very new to Xamarin.Forms & Android, but what I have found makes it sound like a CustomRenderer is what I should be using. However, from what I have seen in the examples I could find, the CustomRenderer only lets you change properties of a Button. I am looking for something more like the Content property or Template property & ControlTemplate that existed in UWP (I have a large background in UWP & am working on converting my apps to Xamarin.Forms). These let you use any elements you wanted for the visual component of the control. I want the same properties & events as a regular Button, but I need to have multiple elements in the visual part of the Button (such as an image, multiple text elements, shapes, etc.). How do I do this? Thanks.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Morgan SOULLEZ 1 Reputation point
    2020-11-25T12:53:10.117+00:00

    Look at the TemplatedView, with that ancestor you can create a fully customizable controls.
    There is an actual Pull Request on the Xamarin.CommunityToolkit for adding the control that you need. You can be inspired by this one to create your own or wait for this PR to be merged.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.