Using Acss.Behaviors

As examples, we provide two built-in behaviours in the current version. Please refer to the behavior for details on how to use them.

  • combobox.popup.align. This behaviour aligns the selected items of a drop-down list to a drop-down box.

  • window.esc.close. This behaviour allows the window to support the corresponding Esc key to close the window.

Installation

dotnet add package Nlnet.Avalonia.Css.Behaviors --version 1.0.0-beta.4

Custom behaviours

  • Import Nlnet.Avalonia.Css.CompileGenerator.

dotnet add package Nlnet.Avalonia.Css.CompileGenerator --version 1.0.0-beta.4
  • Creates a behaviour declaration class, inheriting the AvaloniaObject class and the IBehaviorDeclarer interface.

public partial class CustomA : AvaloniaObject, IBehaviorDeclarer
{
        
}
  • Provides extension classes that use the behaviour declaration class CustomA.

/// <summary>
/// Use customA behavior feature for default css context.
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static AppBuilder UseCustomABehaviorForDefaultContext(this AppBuilder builder)
{
    AcssBuilder.Default.BehaviorResolverManager.LoadResolver(new GenericBehaviorResolver<CustomA>());
    AcssBuilder.Default.BehaviorDeclarerManager.RegisterDeclarer<CustomA>(nameof(CustomA).ToLower());
    AcssBuilder.Default.BehaviorDeclarerManager.RegisterDeclarer<CustomA>(nameof(CustomA));
    return builder;
}
  • Create a custom behaviour class that hangs under the behaviour declaration class CustomA.

  • Use the CustomA behaviour to declare classes in your program.

  • Using behavioural classes in Acss code.

Last updated

Was this helpful?