AvaloniaXT 1.0.0
dotnet add package AvaloniaXT --version 1.0.0
NuGet\Install-Package AvaloniaXT -Version 1.0.0
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="AvaloniaXT" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AvaloniaXT --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AvaloniaXT, 1.0.0"
#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 AvaloniaXT as a Cake Addin #addin nuget:?package=AvaloniaXT&version=1.0.0 // Install AvaloniaXT as a Cake Tool #tool nuget:?package=AvaloniaXT&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AvaloniaXT
Avalonia App Page Helper Dll , Contains MainWindow,SukiUI,Support AOT。
项目组成
- AvaloniaXT Nuget通用页面程序集,包含主窗口和一些通用的扩展方法。
- XTExternalPage 扩展界面程序集,包含定制化的业务界面。
- AvaloniaXT.Desktop 桌面程序启动入口,android和ios没有测试过。
- SukiUI 引用的SukiUI项目 修改了ProgressBar的MiniHeight。
系统界面
AOT支持
要点
- 不使用反射
- 编译绑定必须置为true
<AvaloniaUseCompiledBindingsByDefault>true<AvaloniaUseCompiledBindingsByDefault>
- 反序列化使用源映射
// 提供GetJsonOptions静态方法
var options = UrlUtilities.GetJsonOptions();
options.TypeInfoResolver = ApiJsonContext.Default;
var result = JsonSerializer.Deserialize<AdminCodeResult<EcsMainView>>(data, options);
[JsonSerializable(typeof(AdminCodeResult<EcsMainView>))]
public partial class ApiJsonContext: JsonSerializerContext
{
}
SQL ORM
- 测试使用FreeSQL,Npgsql需升级到最新版本。
- 需要在启动项目中包含rd.xml
// 项目中包含
<ItemGroup>
<RdXmlFile Include="rd.xml" />
</ItemGroup>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="XTExternalPage" Dynamic="Required All">
</Assembly>
<Assembly Name="FreeSql" Dynamic="Required All">
</Assembly>
<Assembly Name="Npgsql" Dynamic="Required All">
</Assembly>
</Application>
</Directives>
AvaloniaXT使用步骤
安装完 AvaloniaXT Nuget包后
1、启动入口 添加 Font Awesomon支持(可选)
public static AppBuilder BuildAvaloniaApp()
{
Register.AddIcons();
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
// 页面中使用
<i:Icon Value="{Binding Condition}" FontSize="{Binding Width}" />
2、在App.xaml中添加页面选择器、样式、底部托盘(可选)
- 页面和弹窗VM都需要继承XTBasePage(提供GetView()方法,注入视图),弹窗还需要重写IsDialog()方法,返回true。
<Application.DataTemplates>
<xt:ViewLocator/>
</Application.DataTemplates>
<Application.Styles>
<sukiUi:SukiTheme ThemeColor="Blue" />
<avalonia:MaterialIconStyles />
</Application.Styles>
// 项目中包含资源,使用方式
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
<TrayIcon.Icons>
<TrayIcons>
<TrayIcon Icon="/Assets/alarm.ico" Clicked="NativeMenuItem_Show"
ToolTipText="AvaloniaXT">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Header="Settings">
<NativeMenu>
<NativeMenuItem Header="Show" Click="NativeMenuItem_Show" />
<NativeMenuItem Header="Exit" Click="NativeMenuItem_Click" />
</NativeMenu>
</NativeMenuItem>
</NativeMenu>
</TrayIcon.Menu>
</TrayIcon>
</TrayIcons>
</TrayIcon.Icons>
private void NativeMenuItem_Click(object? sender, EventArgs e)
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
{
lifetime?.Shutdown();
}
}
private void NativeMenuItem_Show(object? sender, EventArgs e)
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
{
var window = lifetime?.MainWindow;
window.WindowState = WindowState.Normal;
window.Show();
}
}
3、在App中注入服务
var services = new ServiceCollection();
// 注入 AvaloniaXT中的服务
services.InitialXTServices();
// 注入业务界面服务
// services.AddSingleton<DbService>();
_provider = services.BuildServiceProvider();
public override void OnFrameworkInitializationCompleted()
{
// 添加 AvaloniaXT 的方法
ApplicationLifetime?.InitialCompleted(_provider);
base.OnFrameworkInitializationCompleted();
}
辅助方法
视图选择器
public class EcsTagSelector : DataTemplateSelector
{
public override string GetKey(object? param)
{
var tag = param as UnitTagModel;
return tag.Type.ToString();
}
}
<ItemsControl.DataTemplates>
<selector:EcsTagSelector>
<DataTemplate x:Key="Other">
<cp:UnitOther></cp:UnitOther>
</DataTemplate>
</selector:EcsTagSelector>
</ItemsControl.DataTemplates>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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.
-
net8.0
- Avalonia (>= 11.0.6)
- Avalonia.Diagnostics (>= 11.0.6)
- Avalonia.Fonts.Inter (>= 11.0.6)
- CommunityToolkit.Mvvm (>= 8.2.2)
- Material.Icons.Avalonia (>= 2.1.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Projektanker.Icons.Avalonia.FontAwesome (>= 9.0.1)
- SukiUI (>= 5.1.2)
- XT.Common (>= 1.1.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AvaloniaXT:
Package | Downloads |
---|---|
TZ.ViewDataServices_33
33工厂-使用.net8平台开发的一个针对ECS调度大屏的数据服务,包含获取视图和点位信息的API接口服务和实现数据轮询刷新的MQTT服务,支持AOT模式。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 204 | 1/25/2024 |