Skip to content

Conversation

@zacfromaustinpowder
Copy link

@zacfromaustinpowder zacfromaustinpowder commented Oct 30, 2025

What does the pull request do?

Suggested fix for #19943

What is the current behavior?

Explained in #19943

What is the updated/expected behavior with this PR?

Explained in #19943

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

Changed ValidateNestingSelector to call recursively, walking up the hierarchy of parent selectors. This means function overrides are taken into account when walking up the tree. Now if a leaf selector has an OrSelector as its parent, it doesn't throw an exception.

Checklist

Breaking changes

Should not break anything.

Fixed issues

Fixes #19943

…rating up through parent selectors

Changed ValidateNestingSelector to call recursively, walking up
the hierarchy of parent selectors. This means function overrides
are taken into account when walking up the tree. Now if a
selector has an OrSelector as its parent, it doesn't throw an
exception.
@avaloniaui-bot
Copy link

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

@MrJul MrJul added enhancement backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Nov 3, 2025
@MrJul
Copy link
Member

MrJul commented Nov 3, 2025

As mentioned in #19943 (comment), this isn't a valid syntax in XAML right now. We don't even support parenthesis, e.g. Button, TextBox is valid but (Button, TextBox) isn't.

Like Max, I'm not against it (we can enable that syntax in XAML later), this should still be kept in mind. ToString() will now output a selector that can't be parsed back.

{
_selectorString = _parent.ToString(owner) + " > ";
_selectorString = _parent is OrSelector ?
$"({_parent.ToString(owner)}) > " :
Copy link
Member

Choose a reason for hiding this comment

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

Note: all selectors have been modified to add parenthesis around OrSelector, why not add this directly to OrSelector.ToString()? You could add an internal override taking a flag to avoid adding parenthesis around an OrSelector being placed at the root level.

Copy link
Author

Choose a reason for hiding this comment

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

I could do that if you want. I'd still have to change all of the other selectors to check if it's an OrSelector and to invoke the internal override with the extra parameter. Just to be clear, the idea is that parenthesis are redundant when the OrSelector is the only selector.

Copy link
Member

Choose a reason for hiding this comment

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

What I meant is to have a method like internal virtual string ToString(Style owner, bool hasChild) on Selector and just call that with hasChild: true in every child selector without checking for the parent. Then override it in OrSelector to add the parenthesis according to hasChild.

Copy link
Author

Choose a reason for hiding this comment

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

Done 👍

@avaloniaui-bot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improvements to Selector syntax in "code behind"

3 participants