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 applying order #2788

Closed
Axavo opened this issue Jul 29, 2019 · 6 comments
Closed

Styles applying order #2788

Axavo opened this issue Jul 29, 2019 · 6 comments

Comments

@Axavo
Copy link

Axavo commented Jul 29, 2019

Styles applied to an element not in the order they are declared in xaml, or the complexity of their selectors. In exаmple "Maximize" button have to be hidden, but it is not.
AvaloniaApplication1.zip

@kekekeks
Copy link
Member

The last CustomWindow-related selector in Theme.xaml

  <Style Selector="l|CustomWindow[CanResize=false] /template/ Button#PART_MaximizeButton">
    <Setter Property="IsVisible" Value="False" />
  </Style>

should hide the maximize button, when CanResize=False, but it doesn't

@grokys
Copy link
Member

grokys commented Jul 29, 2019

You seem to be setting IsVisible = true as a local value in the template in Theme.xaml:

<Button x:Name="PART_MaximizeButton"
        IsVisible="True"
        Classes="WindowTitleButton">
  <TextBlock Text="Max"/>
</Button>

Local values have a higher priority than styles, so it will always be true.

@grokys grokys closed this as completed Jul 29, 2019
@grokys
Copy link
Member

grokys commented Jul 29, 2019

By the way, this is the same behavior as WPF/UWP.

We would like to improve the experience here, by setting properties in control templates with Style priority, but we've been unable to do that with Portable.Xaml. Now we have our own XAML compiler we hope to improve this in future.

@Axavo
Copy link
Author

Axavo commented Jul 29, 2019

The workaround is to remove the property from the template and add it to another style?

@grokys
Copy link
Member

grokys commented Jul 29, 2019

In this case you just need to remove IsVisible="True" from the Button, as true is the default value.

In general, yes, you should add the default value to a style so it can be overridden, e.g.

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Default/ListBoxItem.xaml#L26-L28

@kekekeks
Copy link
Member

#2789

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

No branches or pull requests

3 participants