0

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).

halfer
  • 19,824
  • 17
  • 99
  • 186
M Yil
  • 877
  • 1
  • 14
  • 35

1 Answers1

1

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.

Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22
  • Thank you for your response. To be sure: I need to place this code in a custom control and setup the binding via the codebehind of the custom control. Then use this custom control in my contentpage and do the binding? Am i understanding you correctly? – M Yil Apr 07 '20 at 09:34
  • Yes , I set the color and text as static value just for demo .You could set them as you want . – Lucas Zhang Apr 07 '20 at 09:35
  • And also, at run-time I want to decide which custom control to take, what can I use for that? A valueconverter? Or? – M Yil Apr 07 '20 at 09:36
  • "Of course , it's up to you", But what control should be made and changed to the run-time-picked control? A boxview? A label? I mean, I need to return the new custom control and set it to a control that is already defined right? This would be my last question. – M Yil Apr 07 '20 at 09:40
  • You could use control template . – Lucas Zhang Apr 07 '20 at 09:41
  • I really can't figure it out, this is the last problem I am running against.. at this point I just created a contenttype object in the xaml file. It has a converter, the converter returns a custom control based on a specific value. But the problem is that I cannot bind with the binding properties because it is a contenttype rather than the specific custom control... – M Yil Apr 07 '20 at 10:39
  • https://stackoverflow.com/questions/61078403/xamarin-forms-create-show-custom-control-based-on-a-condition – M Yil Apr 07 '20 at 10:56