Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTrigger: Evaluate the binding's initial value like WPF #11

Closed
gsivorot opened this issue Dec 11, 2018 · 14 comments
Closed

DataTrigger: Evaluate the binding's initial value like WPF #11

gsivorot opened this issue Dec 11, 2018 · 14 comments

Comments

@gsivorot
Copy link

I have a class that overrides DataTrigger's OnAttached/OnDetaching methods to subscribe/unsubscribe to the AssociatedObject's Loaded event so I can call EvaluateBindingChange to set the initial value of the DataTrigger similar to WPF.

@brianlagunas
Copy link
Collaborator

I'm sorry, but I do not understand what you are asking for. Could you please elaborate on the scenario, and provide as much context as possible. Preferably, please provide a sample application that demonstrates your issue.

@gsivorot
Copy link
Author

Sorry, here’s a better description of the issue:
https://stackoverflow.com/questions/6508098/silverlight-datatrigger-not-firing-on-load

I can still put together a sample if needed.

@brianlagunas
Copy link
Collaborator

Yes, please put together a sample and explain in detail what you're looking for. You lost me at Silverlight :)

@gsivorot
Copy link
Author

Haha, fair enough. I’ll put one together in the morning.

@gsivorot
Copy link
Author

DataTrigger.zip

@brianlagunas
Copy link
Collaborator

Ahh, I see what you mean now. This is actually by design. The issue here is Property Value Precedence.

You are setting the Foreground directly on the TextBlock. This explicit property will override any value set by the trigger. The reason it works in your "WPF DataTrigger" example is because you are setting the Foreground and DataTrigger in a style.

So essentially, we need a way to opt-in to evaluating an explicitly set value.

@gsivorot
Copy link
Author

The Property Value Precedence shouldn't matter should it? ChangePropertyAction sets the property directly (unlike a Style). The issue is the Blend DataTrigger doesn't compute the initial value of Binding. You have to hook up to the AttachedObject Loaded event to set the initial value (the FixedDataTrigger class in my example).

@brianlagunas
Copy link
Collaborator

Honestly, that was my initial guess. I haven't actually debugged the code yet. I see the issue you have though. Definitely something that needs to be fixed.

@gsivorot
Copy link
Author

Looking at it more, it may be due to the fact that the Visual Tree isn't done being constructed when it evaluates the initial value so it can't set the property, hence why using the loaded event for the associated object works.

@brianlagunas
Copy link
Collaborator

That would make sense. I am worried about any backwards compatibility/performance issues by adding that event though. This might have to be an opt-in change.

@gsivorot
Copy link
Author

Yeah, I can definitely see the change having the potential to break old code so that makes sense.

@brianlagunas
Copy link
Collaborator

See PR #64. I think this will fix the problem.

@gsivorot
Copy link
Author

gsivorot commented Dec 7, 2019

Amazing, thanks!

@brianlagunas
Copy link
Collaborator

brianlagunas commented Dec 12, 2019

Fixed via #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants