What you can do is split the solution to this problem into several levels:
First create a bindable property for this check box and call it Validated. I wrote a snippet for it, but didnβt actually compile it, so you can change it if it doesnβt work.
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create<CheckBox, bool> (w => w.IsChecked, false); public bool IsChecked{ get { return GetValue (FooProperty); } set { SetValue (FooProperty, value); } }
Secondly, in the view model, the bool property has a change notification
private bool _isChecked; public bool IsChecked { get { return _isChecked; } set { _isChecked = value; RaisePropertyChanged("IsChecked"); } }
Thirdly, bind your bindable property to the "isChecked" checkbox with one in the view model in your xaml:
<StackLayout> <Checkbox IsChecked = "{Binding IsChecked}"/> </StackLayout>
Fourth, buttons in Xaml with MVVM are associated with commands. and in these commands for them there is a bool property that represents "CanExecute", which basically turns the button on or off. therefore, what you need to do in Xaml is to bind the button command to the command in Model View (allows you to call ClickCommand). And ClickCommand CanExecute is actually a method that returns the value "IsChecked". This will force us to change the installer of the "IsChecked" property, so every time it changes, it must notify the command to check the CanExecute property.
So the final code will be something like
public TermsAndConditionsViewModel() { NextCommand = new Command(ExecuteNextCommand,CanExecuteNextCommand); OnCheckBoxTapChanged = new Command(CheckBoxTapped); } private bool _isChecked; public bool IsChecked { get { return _isChecked;} set { _isChecked = value; NextCommand.ChangeCanExecute();
And xaml will look like
<StackLayout> <Checkbox IsChecked = "{Binding IsChecked}"/> <Button Text= "Next" Command = "{Binding NextCommand}"/> </StackLayout>