Nlnet.Avalonia.Css 1.0.0-beta.1

This is a prerelease version of Nlnet.Avalonia.Css.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Nlnet.Avalonia.Css --version 1.0.0-beta.1                
NuGet\Install-Package Nlnet.Avalonia.Css -Version 1.0.0-beta.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nlnet.Avalonia.Css" Version="1.0.0-beta.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nlnet.Avalonia.Css --version 1.0.0-beta.1                
#r "nuget: Nlnet.Avalonia.Css, 1.0.0-beta.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Nlnet.Avalonia.Css as a Cake Addin
#addin nuget:?package=Nlnet.Avalonia.Css&version=1.0.0-beta.1&prerelease

// Install Nlnet.Avalonia.Css as a Cake Tool
#tool nuget:?package=Nlnet.Avalonia.Css&version=1.0.0-beta.1&prerelease                

See here for Acss.

Nlnet.Avalonia.Css

This is the core of Acss. It provides the abilities to load Acss files, create avalonia styles and manage the lifecycle of them.

Core Process

The Acss follows the process in the image below.

  1. You could create your own AcssBuilder object or use default static AcssBuilder object. Every AcssBuilder object works in their own scope without interaction.

  2. After creating the builder, all type resolvers should be loaded. If custom resource types should be used, also load them in this period. The following step like creating rider settings will be affected by the resolvers. All types mapped will become keyword for rider settings.

  3. All resources should be loaded before any styles. Also it is important that the resources those are dependency of other resources should be loaded first.

  4. Then styles could be loaded.

⚠️ WARNING

The best practice is managing your *.acss files in your own private folders to avoid interfering with other libraries.

For example, if you load *.acss files by LoadFolder method, you may load unexpected files that mixed in the folder. DO NOT DO THIS!

acss process

Editor

  • For rider users, build the rider settings file with code below. We do not provide rider plugin to support Acss language till now. Use this for a temporary replacement. After settings file created, you should restart the rider to apply the settings.
AcssBuilder.Default.TryBuildRiderSettingsForAcss(out _, out _, null);

Note that the rider settings is related to the AcssBuilder object. It means for different builder objects, the settings will be different.

  • Alternatively you can use Visual Studio Code as Acss editor with the extension 'avalonia-css-extension', which is also a shabby version now.

Usage

  • Installation.
dotnet add package Nlnet.Avalonia.Css --version 1.0.0.0
  • Use default Acss builder in Avalonia's AppBuilder. Then load all types. Alternatively, you can create your own Acss builder instead.
private static AppBuilder BuildAvaloniaApp()
{
    return AppBuilder.Configure<App>()
        .UsePlatformDetect()
        ...
        
        // Use default avalonia css builder.
        .UseAcssDefaultBuilder()
        
        // Type resolver for 'Your.Lib'. The GenericTypeResolver<T> will load all types 
        // those belong to the assembly who contains the T class.
        .WithTypeResolverForAcssDefaultBuilder(new GenericTypeResolver<Icon>())
}
  • Initialize the builder. In this section, you can setup the configuration like theme, create rider settings and load Acss files.
private class void Initialize()
{
    ...
	
    // [Optional] Set the current theme.
    AcssBuilder.Default.Configuration.Theme = "blue";
    
    // [Optional] Create rider settings for this Acss builder.
    AcssBuilder.Default.TryBuildRiderSettingsForAcss(out _, out _, null);
    
    // Load acss files. You can keep the cssFile for more operations.
    var loader = AcssBuilder.Default.BuildLoader();
	var cssFile = loader.Load(Application.Current.Styles, "Acss/app.acss");
    
    // Or load acss files from a folder.
    loader.LoadFolder(this, "Acss/");
    
    ...
}

More detail about using of Acss, see the code of Nlnet.Avalonia.Css.App or Nlnet.Avalonia.Css.Fluent.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Nlnet.Avalonia.Css:

Package Downloads
Nlnet.Avalonia.Css.Fluent

Provide fluent themes for Avalonia.Controls, Nlnet.Avalonia.Senior, Nlnet.Avalonia.MessageBox.

Nlnet.Avalonia.Css.Behaviors

Extend avalonia css with behaviors.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 196 3/16/2024
1.0.0 412 11/6/2023
1.0.0-beta.3 100 8/27/2023
1.0.0-beta.2 72 8/23/2023
1.0.0-beta.1 144 8/16/2023