SuncodeSoftware.SuperSDK.UI 2.8.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SuncodeSoftware.SuperSDK.UI --version 2.8.1
                    
NuGet\Install-Package SuncodeSoftware.SuperSDK.UI -Version 2.8.1
                    
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="SuncodeSoftware.SuperSDK.UI" Version="2.8.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SuncodeSoftware.SuperSDK.UI" Version="2.8.1" />
                    
Directory.Packages.props
<PackageReference Include="SuncodeSoftware.SuperSDK.UI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SuncodeSoftware.SuperSDK.UI --version 2.8.1
                    
#r "nuget: SuncodeSoftware.SuperSDK.UI, 2.8.1"
                    
#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.
#:package SuncodeSoftware.SuperSDK.UI@2.8.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SuncodeSoftware.SuperSDK.UI&version=2.8.1
                    
Install as a Cake Addin
#tool nuget:?package=SuncodeSoftware.SuperSDK.UI&version=2.8.1
                    
Install as a Cake Tool

SuperSDK.UI

Avalonia UI 通用组件库,提供常用的 UI 组件和工具。

🎯 核心功能

  • ViewModelBase - ReactiveUI 基类,自动集成 MessageBus 清理
  • GzNotification - 通知管理器(单例模式,支持多窗口)
  • UIHelper - 统一风格的对话框工具
  • UIThreadHelper - UI 线程调度工具

📦 依赖

  • SuperSDK.Core (MessageBus 集成)
  • Avalonia 11.2.2
  • Avalonia.ReactiveUI 11.2.2

🚀 快速开始

1. ViewModelBase 使用

using SuperSDK.UI;
using ReactiveUI;

public class MyViewModel : ViewModelBase
{
    private string _name = "";
    
    public string Name
    {
        get => _name;
        set => this.RaiseAndSetIfChanged(ref _name, value);
    }
    
    public override void RegisterMsg()
    {
        // 注册消息订阅(析构时自动取消订阅)
        MessageBus.Subscribe<MyMessage>(this, OnMyMessage);
    }
    
    private void OnMyMessage(MyMessage msg)
    {
        Name = msg.Value;
    }
}

2. GzNotification 通知系统

初始化(在主窗口):

using SuperSDK.UI;

public class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        
        // ⚠️ 重要:设置通知的TopLevel
        GzNotification.Instance.SetTopLevel(this);
    }
}

显示通知:

using Avalonia.Controls.Notifications;
using SuperSDK.UI;

// 成功通知
GzNotification.Instance.Show(
    "操作成功", 
    "数据已成功保存", 
    NotificationType.Success
);

// 错误通知
GzNotification.Instance.Show(
    "操作失败", 
    "无法连接到数据库", 
    NotificationType.Error
);

// 警告通知
GzNotification.Instance.Show(
    "警告", 
    "配置文件缺失,使用默认配置", 
    NotificationType.Warning
);

// 信息通知
GzNotification.Instance.Show(
    "提示", 
    "系统正在更新...", 
    NotificationType.Information
);

3. UIHelper 对话框

using SuperSDK.UI;

// 错误对话框(红色风格)
await UIHelper.GzShowErrorMsg(
    "加载错误", 
    "文件不存在或已损坏",
    parentWindow: this,
    logSource: "MyApp"
);

// 警告对话框(黄色风格)
await UIHelper.GzShowWarningMsg(
    "警告", 
    "此操作无法撤销,是否继续?"
);

// 信息对话框(蓝色风格)
await UIHelper.GzShowInfoMsg(
    "提示", 
    "文件已成功保存"
);

自动功能:

  • ✅ 自动记录日志到 MessageBus
  • ✅ 统一的 Material Design 风格
  • ✅ 圆角、阴影、动画效果
  • ✅ 自动居中显示
  • ✅ 阻塞式等待用户确认

4. UIThreadHelper 线程调度

using SuperSDK.UI;

// 在 UI 线程上执行操作
await UIThreadHelper.RunOnUIThread(() =>
{
    StatusText = "更新完成";
    ProgressValue = 100;
});

// 从后台线程更新 UI
Task.Run(async () =>
{
    var result = await DoHeavyWork();
    
    await UIThreadHelper.RunOnUIThread(() =>
    {
        ResultText = result;
    });
});

5. GzTitleBarCtrl 自定义标题栏

GzTitleBarCtrl 是一个基于 ViewModelBase 的自定义标题栏控件,提供了统一的窗口标题栏样式和窗口控制功能。

在 AXAML 中使用:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:views="clr-namespace:SuperSDK.UI.Views;assembly=SuperSDK.UI"
        x:Class="MyApp.MainWindow"
        SystemDecorations="None"
        Background="Transparent"
        TransparencyLevelHint="Transparent">
    
    <Border Background="#1E1E1E" CornerRadius="6">
        <Grid RowDefinitions="Auto,*">
            
            <views:GzTitleBarCtrl Grid.Row="0"
                                  Title="我的应用程序"
                                  TitleIcon="{Binding AppIcon}"
                                  IsMaxEnabled="True"
                                  IsMinEnabled="True"
                                  IsCloseEnabled="True" />
            
            
            <ContentControl Grid.Row="1" Content="{Binding CurrentView}" />
        </Grid>
    </Border>
</Window>

处理窗口关闭事件:

GzTitleBarCtrl 的关闭按钮会触发父窗口的 Closing 事件,您只需在窗口的构造函数中监听此事件即可:

public partial class MyWindow : Window
{
    public MyWindow()
    {
        InitializeComponent();
        
        // 方式1:直接关闭前确认
        Closing += async (sender, args) =>
        {
            args.Cancel = true; // 取消默认关闭
            
            var result = await UIHelper.GzShowConfirmDialog(
                "确认退出", 
                "是否确定要关闭窗口?",
                this
            );
            
            if (result)
            {
                Closing -= Closing; // 移除事件避免循环
                Close();
            }
        };
        
        // 方式2:隐藏窗口而不是关闭(如调试窗口)
        // Closing += (sender, args) =>
        // {
        //     args.Cancel = true;
        //     Hide();
        // };
    }
}

🔧 高级功能

// 指定目标窗口显示通知 GzNotification.Instance.Show( "设置已保存", "配置将在下次启动时生效", NotificationType.Success, targetTopLevel: settingsWindow );


### 自定义通知位置

```csharp
using Avalonia.Controls.Notifications;

GzNotification.Instance.Show(
    "新消息", 
    "您有一条新的系统消息",
    NotificationType.Information,
    position: NotificationPosition.BottomRight
);

📝 架构说明

MessageBus 集成:

  • ViewModelBase 析构时自动调用 MessageBus.UnsubscribeAll(this)
  • UIHelper 对话框自动通过 MessageBus.Pub() 发送日志
  • 所有 UI 组件无缝集成消息总线

线程安全:

  • GzNotification 采用单例模式(线程安全)
  • UIThreadHelper 确保 UI 操作在主线程执行
  • 支持多窗口场景的通知管理

📝 License

MIT License - See LICENSE file for details

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on SuncodeSoftware.SuperSDK.UI:

Package Downloads
SuncodeSoftware.SuperSDK.App

Application foundation framework for Avalonia-based Goes applications

SuncodeSoftware.SuperSDK.Canvas

SuperSDK Canvas - 开箱即用的 Avalonia 画布组件,支持设备绘制、连线管理、缩放平移等功能

GoesSoftware.SuperSDK.Canvas

SuperSDK Canvas - 开箱即用的 Avalonia 画布组件,支持设备绘制、连线管理、缩放平移等功能

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.7.1 0 2/6/2026
3.7.0 0 2/6/2026
3.6.0 0 2/6/2026
3.5.0 0 2/6/2026
3.4.0 35 2/5/2026
3.3.0 28 2/5/2026
3.2.0 29 2/5/2026
3.1.1 30 2/5/2026
3.1.0 31 2/5/2026
3.0.0 44 2/5/2026
2.8.5 102 2/3/2026
2.8.4 108 2/3/2026
2.8.2 104 2/3/2026
2.8.1 109 2/3/2026
2.8.0 105 2/3/2026
2.7.0 105 2/3/2026
2.6.1 106 2/3/2026
2.6.0 112 2/3/2026
2.5.0 110 2/3/2026
2.4.0 114 2/2/2026
2.3.0 123 1/16/2026
2.2.0 124 1/16/2026
2.1.0 127 1/16/2026
2.0.8 121 1/15/2026
2.0.7 113 1/15/2026
2.0.6 125 1/15/2026
2.0.5 119 1/15/2026
2.0.4 120 1/15/2026
2.0.3 126 1/15/2026
2.0.2 119 1/15/2026
2.0.1 120 1/15/2026
2.0.0 129 1/15/2026
1.2.6 217 12/23/2025
1.2.5 211 12/23/2025
1.2.4 209 12/23/2025
1.2.2 209 12/23/2025
1.2.1 214 12/22/2025
1.2.0 210 12/22/2025
1.1.8 202 12/22/2025
1.1.7 208 12/22/2025
1.1.6 206 12/22/2025
1.1.5 203 12/22/2025
1.1.4 214 12/22/2025
1.1.3 215 12/22/2025
1.1.2 210 12/22/2025
1.1.1 208 12/22/2025
1.0.7 280 12/16/2025
1.0.6 280 12/16/2025
1.0.5 281 12/16/2025
1.0.4 283 12/16/2025
1.0.3 279 12/16/2025
1.0.2 282 12/16/2025
1.0.1 244 12/15/2025
1.0.0 222 12/15/2025

new about