0

I'm trying to bind a value to the Classes property of some Avalonia Control from within a Style. But I get a Classes is not an AvaloniaProperty error diagnostic.

The example below demonstrates the problem.

<Style Selector="Button">
    <Setter Property="Classes" Value="{Binding MyClasses}" />
</Style>

What is the correct way to bind to Classes from within a Style?

Note that in my application I have a proper reason to bind to the Classes property, unlike in the (contrived) example above which only serves to reproduce the problem.

tyr.bentsen
  • 143
  • 1
  • 6

1 Answers1

0

It is not possible to directly bind to Classes property in Avalonia, but there is a syntax that you might find useful:

<Button Classes.myClass="{Binding MyBoolean}"/>

It allows you to apply a style from the view model. It has been added quite recently and it is not mentioned in the documentation. You can find more details here: https://github.com/AvaloniaUI/Avalonia/pull/5710

radoslawik
  • 915
  • 1
  • 6
  • 14