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

Styles regression - 11.0.x works, 11.1.x / master doesnt #15729

Closed
danwalmsley opened this issue May 15, 2024 · 2 comments
Closed

Styles regression - 11.0.x works, 11.1.x / master doesnt #15729

danwalmsley opened this issue May 15, 2024 · 2 comments

Comments

@danwalmsley
Copy link
Member

danwalmsley commented May 15, 2024

Describe the bug

Styles seem to be applied differently between 11.0.x and 11.1.x

To Reproduce

 <Button Content="Test"
          VerticalAlignment="Stretch"
          Foreground="White"
          Padding="0"
          VerticalContentAlignment="Stretch"
          Cursor="Hand"
          BorderThickness="0"
          Background="Transparent"
          FontSize="16" FontWeight="Bold">
    <Button.Template>
      <ControlTemplate>
        <ContentPresenter Content="{TemplateBinding Content}" 
                          Background="{TemplateBinding Background}">
          <ContentPresenter.Styles>
            <Style Selector="TextBlock">
              <Setter Property="Foreground" Value="{TemplateBinding Foreground}" />
              <Setter Property="FontSize" Value="{TemplateBinding FontSize}" />
              <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
          </ContentPresenter.Styles>
        </ContentPresenter>
      </ControlTemplate>
    </Button.Template>
  </Button>

Expected behavior

On 11.0.x we get.
image

Text is white and bold.

What we get on master / 11.1.x

image

Avalonia version

11.1.x

OS

No response

Additional context

No response

@grokys
Copy link
Member

grokys commented May 15, 2024

Bisected and confirmed caused by #13970.

@grokys
Copy link
Member

grokys commented May 15, 2024

Ok, this one wasn't what I thought it was going to be!

Turns out that in the example above, the template bindings don't work even in 11.0.x. The only reason that they appear to work is that the two properties you're binding: Foreground and FontSize are inherited properties. The white foreground for example isn't coming from the TemplateBinding but is being inherited from the Button. The reason the template bindings don't work is that TextBlock doesn't have a templated parent! It's not part of the Button template - it's the button content.

You can test this out by adding a Tag property on the Button and trying to sett the TextBlock.Tag using a TemplateBinding in a style. The Tag won't be set on the TextBlock in either 11.0 or 11.1.

What changed from 11.0.x to 11.1 is that the failing template bindings now cause the default property value to take effect, blocking the inherited value. That behavior was changed for normal bindings in 11.0.0 (see #10189) but TemplateBinding was missed. #13970 simply made TemplateBinding have the same behavior as normal bindings.

Given that, I think I'm going to close this with "yes it's a breaking change, but the previous behavior was a bug".

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

No branches or pull requests

2 participants