Add a way of setting style classes using bindings
See original GitHub issueWe really need a way to be able to apply to apply style classes to controls based on values from view models. This would be needed to e.g. trigger animations from the view model.
AvaloniaBehaviors has a behavior for this, but I think we should really have something in-box.
A few ideas:
Simple binding
<Button Classes="{Binding ButtonClasses}">
Pros:
- Simple
Cons:
- Will need to either specify actual classes in view model or supply a converter
- Would not be able to specify classes in XAML as well as get them from the binding
Class Setters
<Button>
<Button.Classes>
<ClassSetter Name="foo"/>
<ClassSetter Name="animated" Trigger="{Binding IsButtonAnimating}"/>
</Button.Casses>
</Button>
Access DataContext from Selectors
An alternative to binding classes would be to allow selectors to select into the DataContext.
Pros:
- Probably pretty flexible
Cons:
- Syntax?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:27
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Class and style binding
Use class and style bindings to add and remove CSS class names from an element's class attribute and to set styles dynamically.
Read more >Class and Style Bindings
Since class and style are both attributes, we can use v-bind to assign them a string value dynamically, much like with other attributes....
Read more >Javafx, add style to styleclass using bindings
I want to bind some styles to a TableCell 's StyleClass when a condition is true, so I tried similar way that the...
Read more >The "class" and "css" bindings
The class and css bindings add or remove one or more named CSS classes to the associated DOM element. This is useful, for...
Read more >Attribute, Class, and Style Bindings - Angular Guide
This guide will help you to understand the differences between and how to use attribute, class, and Style binding in more depth.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Implemented with https://github.com/AvaloniaUI/Avalonia/pull/5710
New syntax is:
Just created behavior for this. Hope it will be useful for somebody https://gist.github.com/maxkatz6/2c765560767f20cf0483be8fac29ff22