How to use checkbox control in xamarin.forms?

MjDhaneshMjDhanesh INMember ✭✭

I Follow these steps but still facing the problem

Step 1: add Nuget package called Xlabs.form
step 2:CheckBox chk=new CheckBox()
{
checked=false;
}; in .cs

but still facing problems solution please?....

Answers

  • N_BauaN_Baua INMember ✭✭✭✭✭

    Hi @MjDkMJ ,

    XLab didn't work as expected for me either,
    These controls made my day

    Though documentation is not good, the controls are, you get other bonus like

    Marquee
    RadioGroup
    RadioButtonGroup
    RatingBar
    

    and more

    Hope it helps,

    -- N Baua

  • AlmaJensen.9398AlmaJensen.9398 USMember ✭✭✭

    First of all don't use Xlabs. Is no longer maintained, and even says so on the github repo. XLabs has a ridiculous amount of bugs. You need to either make your own custom renderer, or do a little searching there's a number of other repo's available that have checkbox controls. I've used Labels with font awesome, and a TapGestureRecognizer usually when I need to have a checkbox control.

    @N_Baua @MjDkMJ

    Biggest take away if it says XLABS run away you'll save yourself a ton of pain.

  • SheraShera INMember ✭✭
    edited August 2017

    Hi @MjDkMJ ,
    you can use this custom Control

      public class Checkbox : Button
        {
            public Checkbox()
            {
                base.Image = "Assets/newcbu.png";
                base.Clicked += new EventHandler(OnClicked);
                base.BackgroundColor = Color.Transparent;
                base.BorderWidth = 0;
            }
    
            public static BindableProperty CheckedProperty = BindableProperty.Create(
                propertyName: "Checked",
                returnType: typeof(Boolean?),
                declaringType: typeof(Checkbox),
                defaultValue: null,
                defaultBindingMode: BindingMode.TwoWay,
                propertyChanged: CheckedValueChanged);
    
            public Boolean? Checked
            {
                get
                {
                    if (GetValue(CheckedProperty) == null)
                    {
                        return null;
                    }
                    return (Boolean)GetValue(CheckedProperty);
                }
                set
                {
                    SetValue(CheckedProperty, value);
                    OnPropertyChanged();
                    RaiseCheckedChanged();
                }
            }
    
            private static void CheckedValueChanged(BindableObject bindable, object oldValue, object newValue)
            {
                if (newValue != null && (Boolean)newValue == true)
                   ((Checkbox)bindable).Image = "checkedimage.png";
                else
                    ((Checkbox)bindable).Image = "uncheckedimage.png";      
              }
    
            public event EventHandler CheckedChanged;
            private void RaiseCheckedChanged()
            {
                CheckedChanged?.Invoke(this, EventArgs.Empty);
            }
    
    
            public void OnClicked(object sender, EventArgs e)
            {
                Checked = !Checked;
            }
    
        }
    
    Xaml : <Namespace:Checkbox   Checked="Property you want to Bind" />
    

    hope it helps :smile:

  • Surajit_BeraSurajit_Bera Member ✭✭

    @Shera
    thsnks lot
    I REALLY HAPPY
    IT WORKED FOR ME...

  • DeepakDYDeepakDY INMember ✭✭✭

    Now checkbox control is present in Xamarin.Forms 4.1.0.581479 version.

    Checkbox explanation in this link

    https://devblogs.microsoft.com/xamarin/checkbox-xamarin-forms-4-1-0-pre-release/

Sign In or Register to comment.