Skip to main content
Version: 0.10.x

Binding Classes

In Avalonia, you also can bind classes. Sometimes it could be useful to switch classes depending on some logic, and for those purposes, you can use Binding Classes API. There is the sample usage of Binding Classes. We have two different styles and we want to switch between them depending on MyProperty state.

 <ListBox Items="{Binding MyItems}">
<Style Selector="TextBlock.myClass">
<Setter Property="Background" Value="Red" />
<Style Selector="TextBlock.myClass2">
<Setter Property="Background" Value="Green" />
Classes.myClass="{Binding MyProperty}"
Classes.myClass2="{Binding !MyProperty}"
Text="{Binding Name}"/>

When you bind to classes Avalonia would expect bool value. This API was introduced in 0.10.1