Replies: 2 comments 1 reply
-
Thanks for the proposal - it doesn't actually seem to be that different from #7120 (though that proposal is very barebones) from my understanding. The main things I don't see addressed here are:
|
Beta Was this translation helpful? Give feedback.
1 reply
-
As I work through styling issues I realize how increasingly important this type of change is for Avalonia to scale. It's extremely difficult to manage style fragments for all controls when the ordering matters across many different files. A hierarchy to manage this is sorely needed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Upgraded Styling System
The styling system in Avalonia is extremely powerful in several areas over what was offered in WPF/UWP. A lot of this power comes from Selectors that allow drilling down deep into controls and classes coming from CSS.
The styling system still has a number of shortcoming though. These have been mentioned and discussed all over the place:
In this spec I make an attempt to solve these issues in a backwards-compatible way. Here is a list of the other open discussions:
Proposal
Encapsulating Styles in a single Class
To start, there needs to be some way of encapsulating a style into a single data structure or container. This was first proposed as
ControlTheme
(#7120) and also as aStyleContainer
(#5027 (comment)) orStyleGroup
-- referred to asStyleGroup
going forward. Each of theseStyleGroup
concepts would essentially encapsulate the various existing styles and then requires a type to be specified.Benefits of doing this include:
StyleGroup XAML Example 1
StyleGroup XAML Example 2
All of this said, there is another way that doesn't introduce a new
StyleGroup
class: simply support directly nested styles. It would allow styles to be containerized like a style group. However, aStyleGroup
would only support a single parent-child relationship and not a full hierarchy. Nesting the styles supports a full hierarchy of multiple parent-child relationships.Purely nested styles seems to be the perfect solution to all of this and I don’t think there should be a separate StyleContainer, StyleGroup or ControlTheme at all. Everything should be within Style just like it is in WPF/UWP. Style will get a
Children
orStyles
property to hold the collection of ‘sub-styles’ for each control. This has enormous benefits:Nexted Styles XAML Example
Key Support in Styles
With styles grouped together there still needs to be a way to reference the style as a group. Fundamentally, selectors allow styles to specify a control (style -> control); however, that is only part of a style's usage in other XAML frameworks. Styles actually need to be referenced:
This means the styling system must be extended to support keys directly as a property of the root/parent Style. This allows controls to directly specify which style they would like, overriding any selectors (the type still needs to match)
<Button Style="MyAwesomeButtonStyle"/>
As a side-effect of adding keys, all themes such as fluent will need to specify keys for all the default styles. This is the same as is done in upstream WinUI. Key="DefaultButtonStyle", Key="DefaultTextBlockStyle", etc.
Summary
Most of these ideas are not entirely new. It can be summarized in the below table:
Finally, a brand-new style for Button in an app may look as below and be used with
<Button Style="MyAwesomeButtonStyle"/>
Beta Was this translation helpful? Give feedback.
All reactions