AvaloniaExtensions.Axaml 0.0.2.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package AvaloniaExtensions.Axaml --version 0.0.2.4                
NuGet\Install-Package AvaloniaExtensions.Axaml -Version 0.0.2.4                
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="AvaloniaExtensions.Axaml" Version="0.0.2.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AvaloniaExtensions.Axaml --version 0.0.2.4                
#r "nuget: AvaloniaExtensions.Axaml, 0.0.2.4"                
#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 AvaloniaExtensions.Axaml as a Cake Addin
#addin nuget:?package=AvaloniaExtensions.Axaml&version=0.0.2.4

// Install AvaloniaExtensions.Axaml as a Cake Tool
#tool nuget:?package=AvaloniaExtensions.Axaml&version=0.0.2.4                

AvaloniaExtensions

English | 简体中文

A syntactic sugar library that brings convenience to Avalonia UI development, aiming to enhance development efficiency and experience by providing additional functionality and simplifying common operations.

安装

Install-Package AvaloniaExtensions.Axaml

I18n

Format Requirements: Create an I18n directory in your project and create multilingual resource files Resources[.xx].resx within it as needed. For example, create Resources.resx, Resources.zh-CN.resx, and Resources.ja-JP.resx for English, Simplified Chinese, and Japanese. The demo structure is as follows:

alternate text is missing from this package README image

It is recommended to use ResX Manager to edit resource files for easier management of multilingual resources:

alternate text is missing from this package README image

You can use a T4 template file (such as Language.tt in the demo) to automatically generate C# code for resource keys for easy referencing in your project:

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
//------------------------------------------------------------------------------  
// <auto-generated>  
//     This code was generated by a tool.  
//     Changes to this file may cause incorrect behavior and will be lost if  
//     the code is regenerated.  
// </auto-generated>  
//------------------------------------------------------------------------------
<#
    const string ResourceFileName = "Resources.resx";
#>

namespace <#=System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint").ToString()#>;

public static class Language
{
<#
    var resourceKeys = XElement.Load(this.Host.ResolvePath(ResourceFileName))
        .Elements("data")
        .Select(item => item.Attribute("name")?.Value)
        .Where(item => item != null);

	var resourceDesignerName = Path.GetFileNameWithoutExtension(ResourceFileName);

    foreach (string resourceKey in resourceKeys)
    {
#>
	public static readonly string <#= resourceKey #> = "<#= resourceKey #>";
<#
    }
#>
}

Generated C# code example:

public static class Language
{
	public static readonly string AppName = "AppName";
	public static readonly string Welcome = "Welcome";
}

Usage:

  • Static binding of resource keys:
<TextBlock Text="{i18n:I18n {x:Static l:LanguageKeys.Welcome}}" />
<TextBlock Text="{markup:I18n {x:Static l:Language.RunningCountInfo},Win10}" />
  • Dynamic binding of resource keys:
<TextBlock Text="{i18n:I18n {Binding Title}}" />
  • Switching languages:
I18nManager.Instance.Culture = new CultureInfo(language);

If

Using the Conditional expression in AXAML.

<TextBlock Text="{markup:If Condition={Binding Status}, True=Running, False=NotRunning}" />
<TextBlock Text="{markup:If {Binding Status}, {markup:I18n {x:Static l:Language.Running}}, {markup:I18n {x:Static l:Language.NotRunning}}}" />

Converter Extensions

IfConditionConverter

<markup:IfConditionConverter x:Key="StatusConditionConverter">
            <markup:IfConditionConverter.True>
                <TextBlock Foreground="Green" Text="{markup:I18n {x:Static l:Language.Running}}" />
            </markup:IfConditionConverter.True>
            <markup:IfConditionConverter.False>
                <TextBlock Foreground="DarkOrange" Text="{markup:I18n {x:Static l:Language.NotRunning}}" />
            </markup:IfConditionConverter.False>
        </markup:IfConditionConverter>
<ContentControl Content="{Binding Status, Converter={StaticResource StatusConditionConverter}}" />

Thanks

Taken from open source, contributed to open source. The development of this library was inspired and aided by the following open-source projects or articles:

Special thanks to the contributors of these projects. Their efforts have provided valuable references and assistance for the development of AvaloniaExtensions.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2.8 82 11/13/2024
0.0.2.7 122 9/18/2024
0.0.2.5 132 8/18/2024
0.0.2.4 107 8/18/2024
0.0.2.3 113 8/17/2024
0.0.2.1 124 8/16/2024
0.0.1.1 121 8/15/2024
0.0.1 118 8/14/2024