Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Xamarin Custom Control - How to?

$
0
0

I followed this article to create a basic "custom control" for Xamarin... No joy!
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/contentview

Using this article I simplified the whole thing... I need a very simple control for a mobile reporting app. The current app has LETTER designations (so a Label), in a colored circle (each color means a phase for that designation. Essentially this can be RED, YELLOW, or GREEN... go figure!

I designed a XAML page with a FRAME, and within it is a LABEL... I bound it as is in the article... I set the widthrequest and heightrequest to twice the CornerRadius (i.e a circle)... This control will be databound in a FLEXVIEW ItemSource... This should be easy as heck to accomplish... So far I get no errors, but nothing is rendered on screen...

Xamarin.Essentials 1.5.3.2
Xamarin.Forms 4.6.0.800
.NET Standard Library 2.0.3

All the code is in the article... Here is the XAML

    <Frame BindingContext="{x:Reference this}" WidthRequest="42" HeightRequest="42" HasShadow="False" Padding="0,2" Margin="8" VerticalOptions="Center" HorizontalOptions="Center" BackgroundColor="Transparent" BorderColor="Black" CornerRadius="21">
        <Label Text="{Binding Text, FallbackValue='1'}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontSize="23" FontAttributes="Bold, Italic" />
    </Frame>

public partial class StatusItemControl : ContentView
{
    public static readonly BindableProperty TextProperty = BindableProperty.Create("Text",          // the name of the bindable property
                                                                                typeof(string),         // the bindable property type
                                                                                typeof(StatusItemControl),// the parent object type
                                                                                string.Empty);          // the default value for the property
    public string Text
    {
        get => (string)GetValue(StatusItemControl.TextProperty);
        set => SetValue(StatusItemControl.TextProperty, value);
    }

    public DrawItemControl()
    {
        InitializeComponent();

    }
}

Viewing all articles
Browse latest Browse all 89864

Trending Articles