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

Custom control on androi

$
0
0

Hi,
Hello to all,
I want to create a custom control and I read the online tutorial for PCL .

I created in the PCL

public class TapparellaProgressView : View
{
    //Bindable property for the progress color
    public static readonly BindableProperty ProgressProperty = BindableProperty.Create<TapparellaProgressView, double>(p => p.Progress, 0);

    //Gets or sets the color of the progress bar
    public double Progress
    {
        get { return (double)GetValue(ProgressProperty); }
        set { SetValue(ProgressProperty, value); }
    }

    public TapparellaProgressView()
    {
        
    }
}

and inside the Droid project, i've implemented:

namespace IntelliDomus.Droid.Renders
{
[assembly: ExportRenderer(typeof(TapparellaProgressView), typeof(TapparellaProgressRenderer))]
public class TapparellaProgressRenderer : ViewRenderer
{

    public TapparellaProgressRenderer()
    {
        this.SetWillNotDraw(false);
    }
    public override void Draw(Canvas canvas)
    {
        var el = this.Element as TapparellaProgressView;

        var rc = new Rect();
        GetDrawingRect(rc);

        var pt = new Paint {Color = Color.White, AntiAlias = true};
        var maxHeight = canvas.Height;
        var singleLineHight = maxHeight%3;
        var currentPos = 0;

        var z = el.Progress%3;
        for (int i = 0; i < z; i++)
        {
            var newR = new Rect(rc);
            newR.Bottom = currentPos;
            newR.Top = rc.Height() - (singleLineHight*i);

            canvas.DrawRoundRect(new RectF(newR) , 1,1, pt);
        }

      
    }

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == TapparellaProgressView.ProgressProperty.PropertyName)
            this.Invalidate(); // Force a call to OnDraw
    }
}

}

Into the xaml, i've defined: TapparellaProgressView Progress="40" BackgroundColor="Teal" VerticalOptions="FillAndExpand" WidthRequest="30" />

But the control are not display.
Really, I don't understand.

Thank you in advance


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>