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

Handle $self in compiled binding in multibinding. #14935

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

appel1
Copy link
Contributor

@appel1 appel1 commented Mar 12, 2024

What does the pull request do?

Enables compiled bindings in multibindings.

What is the current behavior?

Compilation error: Avalonia error AVLN:0004: Unable to resolve property or method of name 'FontStyle' on type 'Avalonia.Data.MultiBinding'.

What is the updated/expected behavior with this PR?

That the bindings work the same as when using reflection bindings.

How was the solution implemented (if it's not obvious)?

Tried to do something similar as to how the type is resolved in a style setter.

Fixed issues

Fixes #13528

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0046119-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@@ -123,7 +123,12 @@ IEnumerable<XamlPropertyAssignmentNode> getResourceValues(IXamlAstNode node)
};

var selfType = context.ParentNodes().OfType<XamlAstConstructableObjectNode>().First().Type.GetClrType();


if (context.GetAvaloniaTypes().MultiBinding.IsAssignableFrom(selfType))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a loop to handle nested MultiBindings.
(Granted, it's probably a rare case, but they work in reflection mode.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see as much problem with nested MultiBinding, but more with other markup extensions in general.
Like, Binding inside of OnPlatform extension. Which wouldn't be as rare use case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More generic fix can be added later though. Just to keep in mind.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnPlatform/OnFormFactor both already work with this PR, because they're transformed into special nodes which aren't XamlAstConstructableObjectNode. I couldn't find any other case that the nested MultiBinding one, which is easy to handle. If there are others I'm missing, we can indeed add a more general solution later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, other would be MarkupExtension implementations that don't have special transformer support from the compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nested MultiBindings could be handled by doing this?

  var selfType = context.ParentNodes().OfType<XamlAstConstructableObjectNode>()
      .Select(n => n.Type.GetClrType())
      .Where(t => !context.GetAvaloniaTypes().MultiBinding.IsAssignableFrom(t))
      .First();

@MrJul
Copy link
Member

MrJul commented Mar 15, 2024

Thank you!
Apart from a small edge case, LGTM.

@maxkatz6 maxkatz6 added this pull request to the merge queue Mar 15, 2024
@maxkatz6 maxkatz6 added backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch area-xaml labels Mar 15, 2024
Merged via the queue into AvaloniaUI:master with commit 84b06b2 Mar 15, 2024
6 checks passed
@maxkatz6 maxkatz6 added backported-11.1.x and removed backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch labels Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot bind to self in MultiBinding
4 participants