Bug 37675

Summary: Style PropertyChanged called before the Style is applied
Product: Forms Reporter: Brad Zacher <brad.zacher>
Component: FormsAssignee: Bugzilla <bugzilla>
Severity: normal CC: eric.maupin, jas, rui.marinho, seth.rosetter, stephane.delcroix
Priority: ---    
Version: 2.0.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Tags: AC Style Is this bug a regression?: ---
Last known good build:

Description Brad Zacher 2016-01-14 03:47:21 UTC
For all VisualElement objects, the PropertyChanged event is called *BEFORE* the Style is applied to the object.
This means that any attempts to get properties within the PropertyChanged method will not work.


var label = new Label();
label.PropertyChanged += (sender, args) =>
    if (args.PropertyName == "Style" || args.PropertyName == "TextColor")
        Console.WriteLine(label.TextColor == Color.Red);
label.TextColor = Color.Red;
label.Style = new Style(typeof(Label))
                  Setters =
                      new Setter
                          Property = Label.TextColorProperty,
                          Value = Color.Blue

Will print:

Instead of:

The StyleProperty is constructed with a BindableProperty.PropertyChanged delegate (which refers to the VisualElement.OnStylePropertyChanged method).
However, within the BindableObject.SetValueActual method, BindableProperty.PropertChanged is called *AFTER* BindableObject.OnPropertyChanged.
Comment 1 Rui Marinho 2016-01-20 11:47:58 UTC
Should be fixed in 2.1.0-pre1
Comment 2 Stephane Delcroix 2016-01-22 10:34:54 UTC
The fix won't be in the next release as it was breaking multiple other stuffs.

As always, with events with multiple handlers, the order matters, and the order that's fine for one is probably not for others.

When you receive the PropertyChanged event, you can be sure that the property has changed. There's is no guarantee that the property is fully applied. It's a bit like when you set the Text of a Label, the PropertyChanged event is fired as soon as the property has changed, but that doesn't mean the Layout has adapted yet to the new size of the Label.

We might consider changing that in the future, but it's too much of a breaking change for all of our users right now.

Thanks for understanding this.

the xf team