Xamarin.forms: [Enhancement] Add method to force value coercion

Created on 25 Mar 2019  Â·  5Comments  Â·  Source: xamarin/Xamarin.Forms

Summary

It would be nice to have a method that forces a BindableProperty to be coerced, similar to WPF's CoerceValue method

API Changes

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.

Intended Use Case

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.

help wanted in-progress inactive enhancement âž• up-for-grabs

All 5 comments

@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!

Was this page helpful?
0 / 5 - 0 ratings