LuYao.Avalonia 是一个为 Avalonia UI 框架提供的实用控件和行为库。
| 包名 | 版本 | 描述 |
|---|---|---|
| LuYao.Avalonia.Behaviors | Avalonia 行为库 | |
| LuYao.Avalonia.Fonts.MiSans.Regular | MiSans Regular 字体集成 |
提供一组实用的 Avalonia 行为:
- ImageFromFileBehavior: 从文件路径加载图像,支持最大宽度和高度限制
- 自动处理图像解码和尺寸优化
- 支持动态更新图像源
提供 MiSans Regular 字体的即用集成:
- 一行代码即可配置 MiSans 字体
- 无需手动管理字体文件
提供额外的 Avalonia 控件:
- VirtualizingWrapPanel: 虚拟化环绕面板(开发中)
提供国家旗帜图标控件:
- FlagIcon: 显示国家旗帜的图像控件
- 支持超过 200 个国家/地区代码
- 自动缩放和优化
使用 .NET CLI:
# 安装行为库
dotnet add package LuYao.Avalonia.Behaviors
# 安装 MiSans 字体
dotnet add package LuYao.Avalonia.Fonts.MiSans.Regular或在你的 .csproj 文件中添加:
<ItemGroup>
<PackageReference Include="LuYao.Avalonia.Behaviors" Version="0.*" />
<PackageReference Include="LuYao.Avalonia.Fonts.MiSans.Regular" Version="0.*" />
</ItemGroup>注意: 使用
Version="0.*"会自动获取 0.x 系列的最新版本,避免主版本更新带来的破坏性变更。查看 NuGet 获取最新版本号。
在你的 App.axaml.cs 中:
using Avalonia;
using LuYao.Avalonia.Fonts.MiSans.Regular;
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithMiSansRegularFont() // 添加这一行
.LogToTrace();在 XAML 中:
<Window xmlns="https://github.com/avaloniaui"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:behaviors="clr-namespace:LuYao.Avalonia.Behaviors;assembly=LuYao.Avalonia.Behaviors">
<Image>
<i:Interaction.Behaviors>
<behaviors:ImageFromFileBehavior Source="/path/to/image.jpg"
MaxWidth="800"
MaxHeight="600" />
</i:Interaction.Behaviors>
</Image>
</Window>在 XAML 中:
<Window xmlns="https://github.com/avaloniaui"
xmlns:luyao="https://www.coderbusy.com/luyao">
<StackPanel Orientation="Horizontal">
<luyao:FlagIcon Code="CN" Width="32" />
<luyao:FlagIcon Code="US" Width="32" />
<luyao:FlagIcon Code="JP" Width="32" />
</StackPanel>
</Window># 克隆仓库
git clone https://github.com/coderbusy/luyao-avalonia.git
cd luyao-avalonia
# 恢复依赖
dotnet restore
# 构建项目
dotnet build
# 运行演示(桌面版)
dotnet run --project demo/LuYao.Avalonia.Demo.Desktop本项目采用 MIT 许可证。
欢迎提交问题和拉取请求!
LuYao.Avalonia is a collection of useful controls and behaviors for the Avalonia UI framework.
| Package | Version | Description |
|---|---|---|
| LuYao.Avalonia.Behaviors | Avalonia Behaviors Library | |
| LuYao.Avalonia.Fonts.MiSans.Regular | MiSans Regular Font Integration |
Provides a collection of useful Avalonia behaviors:
- ImageFromFileBehavior: Load images from file paths with support for max width and height constraints
- Automatic image decoding and size optimization
- Dynamic image source updates
Provides ready-to-use MiSans Regular font integration:
- Configure MiSans font with a single line of code
- No need to manually manage font files
Provides additional Avalonia controls:
- VirtualizingWrapPanel: Virtualizing wrap panel (in development)
Provides country flag icon control:
- FlagIcon: Image control for displaying country flags
- Supports 200+ country/region codes
- Automatic scaling and optimization
Using .NET CLI:
# Install Behaviors library
dotnet add package LuYao.Avalonia.Behaviors
# Install MiSans font
dotnet add package LuYao.Avalonia.Fonts.MiSans.RegularOr add to your .csproj file:
<ItemGroup>
<PackageReference Include="LuYao.Avalonia.Behaviors" Version="0.*" />
<PackageReference Include="LuYao.Avalonia.Fonts.MiSans.Regular" Version="0.*" />
</ItemGroup>Note: Using
Version="0.*"will automatically get the latest version in the 0.x series, avoiding breaking changes from major version updates. Check NuGet for the latest version.
In your App.axaml.cs:
using Avalonia;
using LuYao.Avalonia.Fonts.MiSans.Regular;
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithMiSansRegularFont() // Add this line
.LogToTrace();In XAML:
<Window xmlns="https://github.com/avaloniaui"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:behaviors="clr-namespace:LuYao.Avalonia.Behaviors;assembly=LuYao.Avalonia.Behaviors">
<Image>
<i:Interaction.Behaviors>
<behaviors:ImageFromFileBehavior Source="/path/to/image.jpg"
MaxWidth="800"
MaxHeight="600" />
</i:Interaction.Behaviors>
</Image>
</Window>In XAML:
<Window xmlns="https://github.com/avaloniaui"
xmlns:luyao="https://www.coderbusy.com/luyao">
<StackPanel Orientation="Horizontal">
<luyao:FlagIcon Code="CN" Width="32" />
<luyao:FlagIcon Code="US" Width="32" />
<luyao:FlagIcon Code="JP" Width="32" />
</StackPanel>
</Window># Clone the repository
git clone https://github.com/coderbusy/luyao-avalonia.git
cd luyao-avalonia
# Restore dependencies
dotnet restore
# Build the project
dotnet build
# Run the demo (Desktop)
dotnet run --project demo/LuYao.Avalonia.Demo.DesktopThis project is licensed under the MIT License.
Issues and pull requests are welcome!