question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a way of setting style classes using bindings

See original GitHub issue

We 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:closed
  • Created 4 years ago
  • Reactions:27
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
maxkatz6commented, Apr 27, 2021

Implemented with https://github.com/AvaloniaUI/Avalonia/pull/5710

New syntax is:

<Button Classes.myClass="{Binding xxx}"/>
4reactions
maxkatz6commented, Sep 9, 2020

Just created behavior for this. Hope it will be useful for somebody https://gist.github.com/maxkatz6/2c765560767f20cf0483be8fac29ff22

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found