It would be nice to have a method that forces a BindableProperty to be coerced, similar to WPF's CoerceValue method
The BindableObject class would have an additional method called CoerceValue that looks like this:
class BindableObject
{
void CoerceValue(BindableProperty property);
}
When called, this method would coerce the current value of the property if a coerceCallback is set on the property.
This method is useful to coerce a BindableProperty even if the property itself hasn't changed. If you have some sort of TextBox control with a variable DisplayLength property for example, you could adjust the displayed text length by calling the CoerceValue method when the DisplayLength changes without changing the text itself.
@SuNNjek Good news! This already exists. Thanks!
@samhouts I am aware of the callback. What I am suggesting is a method that would force a BindableObject to re-evaluate this callback. There currently seems to be no way to do this that I am aware of.
Essentially this would probably just call this code again https://github.com/xamarin/Xamarin.Forms/blob/50dbbcf55d71f75fa79aa87e8514799b322f3bda/Xamarin.Forms.Core/BindableObject.cs#L341-L342
/cc @StephaneDelcroix
This is a good idea, I also need this!
Hi @samhouts / @StephaneDelcroix ,
I'd like to take this up. I've done my initial analysis and would like to add a method (public void CoerceValue(BindableProperty property); as requested) to BindableObject class to force value coercion. Should we also add a corresponding overloaded method with BindablePropertyKey similar to other public methods like ClearValue, SetValue etc.
Please let me know your initial feedback and if I can go ahead.
Thanks!