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

Adding a style without selector does not locate the target type. #18024

Open
emmauss opened this issue Jan 22, 2025 · 0 comments · May be fixed by #18026
Open

Adding a style without selector does not locate the target type. #18024

emmauss opened this issue Jan 22, 2025 · 0 comments · May be fixed by #18026
Assignees

Comments

@emmauss
Copy link
Contributor

emmauss commented Jan 22, 2025

Describe the bug

When defining styles, if the user wants to reference the Styles owner in a setter, not providing a selector will reference the owner, in other words, it's implicit "self". Currently this doesn't work and crashes when set in xaml with the error
Could not determine target type of Setter Line Y, position X

To Reproduce

Add a style with no selector to a control.

  <UserControl.Styles>
    <Styles>
      <Style>
        <Setter Property="IsVisible" Value="False"/>
      </Style>
    </Styles>
  </UserControl.Styles>

Expected behavior

The setter finds the target type, which is the Styles owner, and sets IsVisible property on the control.
This issue can be worked around by setting x:SetterTargetType on the setter, but as there's an explicit test available for this in code form, xaml should also behave the same: https://github.com/AvaloniaUI/Avalonia/blob/master/tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs#L81 .

Avalonia version

11.2.3

OS

No response

Additional context

No response

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

Successfully merging a pull request may close this issue.

2 participants