0

I tried this code for some reason upon clicking the checkbox it doesnt change the value of the behind.

I found this post but didnt fully understand how it works.

Xaml

<CheckBox Color="#9E9D9B" 
          x:Name="red"
          IsChecked="{Binding RedBool}"/>

Code Behind

public static readonly BindableProperty RedBox = BindableProperty.Create(
propertyName: nameof(RedBool),
returnType: typeof(bool),
declaringType: typeof(NewCraft),
defaultValue: false,
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: changedProperty);

private static void changedProperty(BindableObject bindable, object oldValue, object newValue)
{
    var redBind = (NewCraft)bindable;
    redBind.RedBool = (bool)newValue;
}

public bool RedBool
{
    get => (bool)GetValue(RedBox);
    set => SetValue(RedBox, value);
}
  • 1
    your link is broken. Regardless, why are you creating a `BindableProperty`? That is not necessary, all you need is normal `public bool property`. Also, have you set the `BindingContext` of the page? Bindings do not work without a `BindingContext` – Jason Mar 12 '23 at 16:23
  • Because its an component on another page thats being imported so this in my eyes seems like the way to do it, Is there a better way? where and how would i set the bindingContext? i have `this.BindingContext = red;` in the constructor – ketamine6318 Mar 12 '23 at 17:35
  • that doesn't make sense, because `red` doesn't have a `RedBool` property. I'd try `BindingContext = this;` – Jason Mar 12 '23 at 23:50

0 Answers0