Checkbox checkchanged property not working

CodingNewUserCodingNewUser INMember ✭✭
edited June 2018 in General

Hi,

I am trying to create dynamic check boxes using the Xlabs.Forms.controls nuget.

 else if (item.QuestionType == "CheckBox")
                        {
                            myGrid.Children.Add(new CheckBox
                            {
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                                VerticalOptions = LayoutOptions.Fill,
                                DefaultText = item.Choices[i],
                                FontSize = 14,
                                AutomationId = questioncount.ToString(),
                                CheckedChanged = CheckedChangedbox

                            }, 0, rowCount);

                            rowCount++;
                        }

The property checked changed is not available and keeps giving an error.Attached screenshots.
The class for the Checkbox is as below:-

      using System;
      using Xamarin.Forms;

    namespace XLabs.Forms.Controls
     {
         public class CheckBox : View
         {

          public static readonly BindableProperty CheckedProperty;

          public static readonly BindableProperty CheckedTextProperty;

           public static readonly BindableProperty DefaultTextProperty;

           public static readonly BindableProperty FontNameProperty;

           public static readonly BindableProperty FontSizeProperty;

           public static readonly BindableProperty TextColorProperty;

           public static readonly BindableProperty UncheckedTextProperty;

           public CheckBox();


         public bool Checked { get; set; }

         public string CheckedText { get; set; }

         public string DefaultText { get; set; }

         public string FontName { get; set; }

         public double FontSize { get; set; }

         public string Text { get; }

          public Color TextColor { get; set; }

          public string UncheckedText { get; set; }

          public event EventHandler<EventArgs<bool>> CheckedChanged;
        }
    }
Tagged:

Best Answer

  • CodingNewUserCodingNewUser IN ✭✭
    Accepted Answer

    Worked like this:-

       CheckBox checkbox = new CheckBox();
                                {
                                    checkbox.HorizontalOptions = LayoutOptions.FillAndExpand;
                                    checkbox.VerticalOptions = LayoutOptions.Fill;
                                    checkbox.DefaultText = item.Choices[i];
                                    checkbox.FontSize = 14;
                                    checkbox.AutomationId = questioncount.ToString();
                                    checkbox.CheckedChanged += CheckedChangedbox;
                                    checkbox.StyleId = item.Questions;
                                }
    

Answers

  • Saraswati_ChandraSaraswati_Chandra USMember ✭✭✭

    @CodingNewUser : use += not =

    CheckedChanged = CheckedChangedbox (Wrong)
    CheckedChanged += CheckedChangedbox

  • CodingNewUserCodingNewUser INMember ✭✭
    edited June 2018

    Hi Saraswati,

    I already tried this.Please check the screenshot.

  • Saraswati_ChandraSaraswati_Chandra USMember ✭✭✭
    edited June 2018

    @CodingNewUser In your image one above, intellisense is clearly showing you the name of the property "Checked", So just assign it the value you want, i.e, true or false.

    I replied you on PM, so please see the solution

  • CodingNewUserCodingNewUser INMember ✭✭
    Accepted Answer

    Worked like this:-

       CheckBox checkbox = new CheckBox();
                                {
                                    checkbox.HorizontalOptions = LayoutOptions.FillAndExpand;
                                    checkbox.VerticalOptions = LayoutOptions.Fill;
                                    checkbox.DefaultText = item.Choices[i];
                                    checkbox.FontSize = 14;
                                    checkbox.AutomationId = questioncount.ToString();
                                    checkbox.CheckedChanged += CheckedChangedbox;
                                    checkbox.StyleId = item.Questions;
                                }
    
  • MarcoTronconeMarcoTroncone GBUniversity ✭✭✭

    I've written a good tutorial on checkboxes...
    You can read it and use that code. it's very easy to implement and you don't need external libraries:

    http://www.xamarinexpert.it/2018/03/27/add-a-checkbox-xamarin-forms/

Sign In or Register to comment.