Search code examples
user-interfacexamarin.formscustom-controlscustom-renderer

Xamarin forms - Create complex custom control (create multiple traffic signs)


I have the following screen in an Android project:

enter image description here

How can I create controls like this in Xamarin forms? (I really don't want to implement it native).


Solution

  • You could use Frame and set the Padding and CornerRadius .

    For example

    <StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
    
        <Frame BackgroundColor="Red" CornerRadius="10" WidthRequest="100" HeightRequest="50" Padding="5">
    
    
            <Frame BackgroundColor="White" CornerRadius="8" WidthRequest="90" HeightRequest="40" Padding="5" >
    
                <Frame BackgroundColor="Red" CornerRadius="8" WidthRequest="80" HeightRequest="30" Padding="0">
    
                    <Label Text="11111" TextColor="White"  FontSize="20" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
    
                </Frame>
    
            </Frame>
    
        </Frame>
    
    </StackLayout>
    

    enter image description here

    You could put the above code in a custom view and binding the color and text in code behind.