0

I'm pretty new to Xamarin in general, and I'm working with Xamarin.Forms. I need to create single reusable controls/ui components that look the same across both Android and iOS. Take the following image as an example:

enter image description here

I need a button that looks exactly like this on both Android and iOS. The way that I found out about after some research is to create custom renders. That way it seems like some things about the control can be modified according to the platform.

However I'm wondering if there's another way that doesn't require the usage of extra logic in the platform-specific projects. Could I achieve this entirely in the Xamarin.Forms project? Also, the button it's just an example, I'll need to do this to entry fields, labels, calendars, radio buttons, check boxes and so on.

adamasan
  • 1,092
  • 1
  • 12
  • 33

1 Answers1

4

Depends a bit on the functionality, but in general you can create cross plat controls only in XAML ( and code ) and not use custom renderers.

For example a buton like this could look like this: ( this code example will create a circle button only in XAML )

<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:models="clr-namespace:XamDevSummit.Models"            
             x:Class="XamDevSummit.Controls.FabButton">
    <ContentView.Content>
        <Grid RowSpacing="0" ColumnSpacing="0"
              HeightRequest="50" WidthRequest="50"
              VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <Button x:Name="Fab"
                    CornerRadius="25" BackgroundColor="Olive"
                    Text="{x:Static models:IconFont.XamarinOutline}"
                    Command="{Binding ChatCommand}"
                    Style="{StaticResource MaterialButton}" />
        </Grid>
    </ContentView.Content>
</ContentView>

In regards for you other controls you list up, like I said all depends on what the need is for the look and feel. Some things are only possible with Custom Renderers.

Depechie
  • 6,102
  • 24
  • 46
  • I understand. I was able to do something like this in Xamarin.Forms, but since I had to control the colors (background and text) when the status of the button is disabled, I had do create custom renderers. What bothers me is that now I'm unable to set the CornerRadius on the XAML, I have to do it on the custom renderer for both Android and iOS. But thank you! :) – adamasan Jul 19 '19 at 11:45