AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
24.72k stars 2.14k forks source link

IProvideValueTarget.TargetObject should return the target object and not itself #4601

Open thexamlguy opened 3 years ago

thexamlguy commented 3 years ago

I am attempting to port over this WPF MethodBindingExtension over to Avalonia UI. The only thing that is currently blocking me is that the IProvideValueTarget TargetObject is returning itself (as in the MarkupExtension class) rather than the actual object the MarkupExtension is being used within, i.e. Button. I've compared this behaviour in WPF and I can see that the IProvideValueTarget is returning the correct TargetObject.

Avalonia UI image

WPF image

I can only assume that this is a bug, unless of course Avalonia is correct?

kekekeks commented 3 years ago

Seems like a bug, could you share your project?

kekekeks commented 3 years ago

Also, keep in mind that services should be resolved and consumed before leaving ProvideValue. The IProvideValueTarget instance is reused, so it will contain irrelevant values otherwise.

thexamlguy commented 3 years ago

I've chucked together a quick sample Avalonia UI app containing the relevant codes, hope it helps 👍 AvaloniaApplication1.zip