A change handler is a callback invoked when a bindable property changes. It receives the control, old value, and new value, then updates dependent state. section 11.2.2
Enabling a custom stepper
A custom MildredStepper exposes an IsEnabled bindable property. Its handler casts the new value to bool and applies it to the value Entry, plus button, and minus button. A DataTrigger sets IsEnabled to false when SelectedProduct is null; selecting a product enables the stepper again. section 11.2.2
Implement the pattern in three steps:
- Choose the default value needed after a trigger reverts; here, IsEnabled defaults to true. section 11.2.2
- Define a handler with bindable, oldValue, and newValue parameters. section 11.2.2
- Pass the handler by name using the propertyChanged argument of BindableProperty.Create. section 11.2.2
Listing 11.8 The OnIsEnabledChanged method
private static void OnIsEnabledChanged(BindableObject
bindable, object oldValue, object newValue) #1
{
if (bindable is MildredStepper mildredStepper) #2
{
mildredStepper.IsEnabled = (bool)newValue; #3
mildredStepper.ValueEntry.IsEnabled =
mildredStepper.IsEnabled; #4
mildredStepper.PlusButton.IsEnabled =
mildredStepper.IsEnabled; #4
mildredStepper.MinusButton.IsEnabled =
mildredStepper.IsEnabled; #4
}
}
Use the handler structure as a template for propagating a bindable property value to internal controls. section 11.2.2
