AvaloniaExtensions.Axaml
0.0.2.8
dotnet add package AvaloniaExtensions.Axaml --version 0.0.2.8
NuGet\Install-Package AvaloniaExtensions.Axaml -Version 0.0.2.8
<PackageReference Include="AvaloniaExtensions.Axaml" Version="0.0.2.8" />
paket add AvaloniaExtensions.Axaml --version 0.0.2.8
#r "nuget: AvaloniaExtensions.Axaml, 0.0.2.8"
// Install AvaloniaExtensions.Axaml as a Cake Addin #addin nuget:?package=AvaloniaExtensions.Axaml&version=0.0.2.8 // Install AvaloniaExtensions.Axaml as a Cake Tool #tool nuget:?package=AvaloniaExtensions.Axaml&version=0.0.2.8
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
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:
It is recommended to use ResX Manager to edit resource files for easier management of multilingual resources:
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:
- WpfExtensions: https://github.com/DingpingZhang/WpfExtensions
- I18N:https://github.com/Antelcat/I18N
- WPF或Avalonia使用tt模板和resx文件实现国际化:https://blog.csdn.net/eyupaopao/article/details/136638194
Special thanks to the contributors of these projects. Their efforts have provided valuable references and assistance for the development of AvaloniaExtensions.
Product | Versions 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. |
-
.NETStandard 2.0
- Avalonia (>= 11.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.