AvaloniaUI / Avalonia.Xaml.Behaviors

Port of Windows UWP Xaml Behaviors for Avalonia Xaml.
MIT License
396 stars 48 forks source link

Fix #52 (binding to static object) and #53 (Actions updating after Trigger) #63

Closed ThereGoesMySanity closed 1 year ago

ThereGoesMySanity commented 3 years ago

When a DataTriggerBehavior is bound to a non-static property, the order of initialization looks something like this:

Trigger properties defined in XAML (each calls OnValueChanged) -> Action properties defined in XAML (doesn't call OnValueChanged) -> DataContext (calls OnValueChanged)

However, when a static binding is used, the order of initialization becomes:

Static binding (calls OnValueChanged) -> Trigger properties defined in XAML (each calls OnValueChanged) -> Action properties defined in XAML (doesn't call OnValueChanged)

The important thing to note is that the last thing initialized in the latter case doesn't call OnValueChanged -- because of this, none of the triggers are properly invoked in this case.

To fix this, I added listeners to the ActionsCollection so that all properties of any attached Actions also cause an OnValueChanged call. This also fixes #53, since that was caused by bindings of Actions updating after Triggers were invoked.

Fixes #52 Fixes #53

EDIT: Sometimes AttachedObject is initialized last as well, so there needs to be a call to OnValueChanged in OnAttached() as well.

ThereGoesMySanity commented 3 years ago

Nevermind - this doesn't do what I thought it did.

ThereGoesMySanity commented 3 years ago

Updated - this now works properly.

Tenjim commented 3 years ago

Hi,

There is any update of this PR?

Thank in advance,

wieslawsoltes commented 1 year ago

Conflicts with master branch