AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.58k stars 2.22k forks source link

Allow setting conditional classes via setters #12964

Open SKProCH opened 1 year ago

SKProCH commented 1 year ago

Describe the bug Avalonia has Classes.accent="{Binding IsSpecial}" markup.
https://docs.avaloniaui.net/docs/next/basics/user-interface/styling/style-classes#conditional-classes

But when i try to use it inside of setter if doesn't work and throws compilation error.

<Setter Property="Classes.withClipping" Value="True" />
Error AVLN:0004 Avalonia: Unable to find withClippingProperty field on type Avalonia.Controls.Classes,Avalonia.Base Line 591, position 15.

To Reproduce Steps to reproduce the behavior:

  1. Create a style
  2. Add setter
    <Setter Property="Classes.withClipping" Value="True" />
  3. See error

Expected behavior Classes can be set via style/ControlTheme setters.

Desktop (please complete the following information):

maxkatz6 commented 1 year ago

It's not a bug, but not a supported feature. Initially, it wasn't implemented due to the possibility of a circled loop of classes. I.e. class that disables itself in the style. Problem, that possibly can be ignored, but still would be pretty hard to diagnose.

SKProCH commented 1 year ago

It's not a bug, but not a supported feature. Initially, it wasn't implemented due to the possibility of a circled loop of classes. I.e. class that disables itself in the style. Problem, that possibly can be ignored, but still would be pretty hard to diagnose.

Sounds like if we get a circled loop of classes we also get StackOverflowException, isn't it?

Al12rs commented 10 months ago

Second the request, this would allow avoiding code duplication and reusing Style classes to define styling for child elements. See #13906 for details.