Search code examples
xamarinxamarin.formsxamarin.uwpxlabs

Checkboxes not visible in release mode UWP (Xamarin Forms)


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?


Solution

  • 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