1
votes

I'm completely new to xamarin.forms.

I used XLabs library to add checkboxes in my PCL project (Xamarin Forms).

When I run my app UWP ARM in Debug mode there's no error, but when I run the app in Release mode the checkboxes ARE never shown.

Is there any setting that I need to configure?

1
It seems that this library has some problems, please see this in order to get other approach.ganchito55
I try these solutions but they don't help me.Greta
XLabs are deprecated. Don't use it. For checkbox, why don't you use the Switch control?hugo
Because I need to add a list of answers for a type of question and the Switch control isn't a solution for this of project.Greta

1 Answers

4
votes

As @hugo said that the XLabs library is no longer maintained. It may not work with newer versions of Xamarin.Forms. For your requirement, you could use Switch control to replacing checkbox or use custom checkbox control. The following code implemented a simple checkbox. For more please refer to Introduction to Custom Renderers.

CustomCheckBox.cs

public class CustomCheckBox : View
{
    public static readonly BindableProperty CheckedProperty =
    BindableProperty.Create("Checked", typeof(bool), typeof(CustomCheckBox), default(bool));

    public bool Checked
    {
        get { return (bool)GetValue(CheckedProperty); }
        set { SetValue(CheckedProperty, value); }
    }

}

CustomCheckBoxRenderer.cs

[assembly: ExportRenderer(typeof(CustomCheckBox), typeof(CustomCheckBoxRenderer))]
namespace LabsTest.UWP
{
    public class CustomCheckBoxRenderer : ViewRenderer<CustomCheckBox, Windows.UI.Xaml.Controls.CheckBox>
    {
        protected override void OnElementChanged(ElementChangedEventArgs<CustomCheckBox> e)
        {
            base.OnElementChanged(e);
            if (Control == null)
            {
                SetNativeControl(new Windows.UI.Xaml.Controls.CheckBox());
            }
            if (Control != null)
            {
                Control.IsChecked = Element.Checked;
            }
        }
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (e.PropertyName == nameof(Element.Checked))
            {
                UpdateStatus();
            }
        }
        private void UpdateStatus()
        {
            Control.IsChecked = Element.Checked;
        }
    }
}

Usage

<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
    <local:CustomCheckBox x:Name="MyCheckBox" Checked="True">
    </local:CustomCheckBox>
</StackLayout>

enter image description here