خرید بک لینک

Vote count: 2

So I made a CustomRenderer for my Android part of my app. This CustomRenderer is located in MyProject.Droid and it's called CustomSwitchRenderer which, obviously, is meant for the switches I'm using. So when I tried to test it the switches wouldn't show up in my page. It was just a blank tabbed page with two navigation buttons in it. I find this very wierd since no errors and waings are being thrown. This is what I have:

The Page:

        private  void Doelen() {
        pages.Add (new ContentPage {
            Title="Doelen",
            BackgroundImage="background.jpg",
            Content = new StackLayout {
                Padding = 15,
                BackgroundColor = Color.White,
                Opacity = 0.75,
                Children = {
                    new Label {
                        Text = subjects [2],
                        FontSize = 30,
                        HorizontalOptions = LayoutOptions.Center,
                        VerticalOptions = LayoutOptions.Start,
                        TextColor = Color.White
                    },
                    new Label {
                        Text = "Omzet:",
                        FontSize = 16
                    },
                    ckbOmzet,
                    ckbMarge,
                    ckbNieuwelant,
                    new StackLayout { HorizontalOptions = LayoutOptions.Center, Orientation = StackOrientation.Horizontal, Children = { navButtonPrev, navButtonNext } }
                }
            }
        });
    }

and this is how I defined my switches:

private Switch ckbOmzet = new Switch();
private Switch ckbMarge = new Switch();
private Switch ckbNieuwelant = new Switch();

and ofcourse, my CustomSwitchRenderer class which is located in MyProject.Droid:

[assembly:ExportRenderer(typeof(Switch), typeof(CustomSwitchRenderer))]
namespace MyProject.Droid
{
public class CustomSwitchRenderer : SwitchRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            Control.TextOn = "AAN";
            Control.TextOff = "UIT";

            Android.Graphics.Color enabled = Android.Graphics.Color.Gray;
            Android.Graphics.Color colorON = Android.Graphics.Color.Green;
            Android.Graphics.Color colorOFF = Android.Graphics.Color.Red;

            Control.SetTextColor(Android.Graphics.Color.Black);

            StateListDrawable drawable = new StateListDrawable();

            drawable.AddState(new int[] 
                {
                    Android.Resource.Attribute.StateChecked
                }, new ColorDrawable(colorON));
            drawable.AddState(new int[]
                {
                    Android.Resource.Attribute.StateEnabled
                }, new ColorDrawable(enabled));
            drawable.AddState(new int[]
                {

                }, new ColorDrawable(colorOFF));

            Control.ThumbDrawable = drawable; 
        }

        this.SetNativeControl(Control);
    }
}
}

I have looked at multiple threads and I still don't know what's I'm doing wrong here! Can someone please tell me what I'm doing wrong here?

asked 9 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 9 ارديبهشت 1395 ساعت: 19:59

صفحه بندی