Avalonia Css
Source CodeδΈ­ζ–‡
  • Documentation
    • πŸŽ†Welcome
    • πŸŒοΈβ€β™‚οΈGet started
      • About Acss
      • Processes and concepts
      • Security
      • Performance Evaluation
      • Configuring the development environment
      • Debugging
      • About source code
      • FAQ
    • ❓How-to
      • Using Acss
        • Type Resolution
        • Configuration
        • Code Source
        • Extending Resources
      • Using Acss.Controls
      • Using Acss.Fluent
      • Using MessageBox
      • Using Senior
      • Using Acss.Behaviors
    • πŸ“Acss Syntax
      • Comment
      • Resource
      • Style
      • Animation
      • Behavior
    • πŸ’ŽBest Practices
      • Define a good control template
Powered by GitBook
On this page
  • Local Code Source
  • 1. Loading by document
  • 2. Load from folder
  • Embedded Code Source
  • 1. Single Uri loading
  • 2. Batch Load by Uri

Was this helpful?

Edit on GitHub
  1. Documentation
  2. How-to
  3. Using Acss

Code Source

ISource is the source of Acss source code. Currently we provide two types of code sources, local code sources (FileSource) and embedded code sources (EmbeddedSource).

Acss code files are suffixed with lowercase acss, independent of the type of code source.

Local Code Source

Local code sources use local files as code input. We support two loading methods, load by file or load by directory.

1. Loading by document

var loader = AcssContext.Default.GetService<IAcssLoader>();

var source1 = new FileSource("Acss/Case.acss");
loader.Load(Application.Current.Styles, source1);

// Use prefer path $"{debugRelative}Acss/Case.acss" if it is valid. 
// Or use the path "Acss/Case.acss".
var source2 = new FileSource("Acss/Case.acss", $"{debugRelative}Acss/Case.acss");
loader.Load(Application.Current.Styles, source2);

2. Load from folder

var loader = AcssContext.Default.GetService<IAcssLoader>();

loader.LoadCollection(this, new FileSourceCollection("Acss/"));
loader.LoadCollection(this, new FileSourceCollection("Acss/", "../../Acss/"));

Priority paths are supported whether loading by file or by directory. Priority paths are used first when they are valid. This is useful in a debugging environment.

We can use the directory where the source code is located first, and the directory under the current application as a second choice.

Note that loading by directory does not recurse through directories, it only loads all *.acss files in the current directory of the specified directory.

Embedded Code Source

The embedded resource approach is much more friendly to the way individual files are packaged.

1. Single Uri loading

var loader = AcssContext.Default.GetService<IAcssLoader>();

loader.Load(
    Application.Current.Styles, 
    new EmbeddedSource(
        new Uri("avares://Nlnet.Avalonia.Css.Fluent/Acss/AccentColor.acss"), 
        PreferLocalPath, 
        UseRecommendedPreferSource, 
        AutoExportSourceToLocal));

2. Batch Load by Uri

var loader = AcssContext.Default.GetService<IAcssLoader>();

loader.LoadCollection(
    Application.Current.Styles, 
    new EmbeddedSourceCollection(
        new Uri("avares://Nlnet.Avalonia.Css.Fluent/Acss/"), 
        PreferLocalPath, 
        UseRecommendedPreferSource, 
        AutoExportSourceToLocal));
PreviousConfigurationNextExtending Resources

Last updated 1 year ago

Was this helpful?

We also support embedding code sources into applications as Avalonia resources; see for the usage of the three EmbeddedSource parameters.

❓
How to use Acss.Fluent