# AtomUI 6.0.8 API 变更示例 本文档补充 `6.0.8` 相比 `6.0.7` 的主要 API 变更和迁移写法。正式版本条目见仓库根目录 `CHANGELOG.md` 和 `CHANGELOG.zh-CN.md`。 ## ImagePreviewer 图片源迁移 `6.0.8` 将 ImagePreviewer 的图片源统一到 `IImagePreviewSource`: - `SourceUri` -> `Source` - `SourceUris` -> `Sources` - `FallbackSourceUri` -> `FallbackSource` - URI、本地文件、Avalonia resource 使用 `UriImagePreviewSource` - 数据库、鉴权网络、加密文件、内存数据等按需流使用 `StreamImagePreviewSource` ### 6.0.7 写法 ```xml ``` ### 6.0.8 写法 ```csharp using AtomUI.Desktop.Controls; public IImagePreviewSource PreviewSource { get; } = new UriImagePreviewSource("https://example.com/photo.jpg"); public IImagePreviewSource PreviewFallbackSource { get; } = new UriImagePreviewSource("avares://Demo/Assets/fallback.png"); ``` ```xml ``` ### 多图、封面和预加载 `CoverIndex` 只决定关闭态封面显示哪一张,不会改变 `CurrentIndex`。 ```csharp public IList PreviewImages { get; } = [ new UriImagePreviewSource("https://example.com/photo-1.jpg"), new UriImagePreviewSource("https://example.com/photo-2.jpg"), new UriImagePreviewSource("https://example.com/photo-3.jpg") ]; public int CurrentPreviewIndex { get; set; } ``` ```xml ``` ### 懒加载数据流 `OpenReadAsync` 每次调用都应返回新的可读流,返回流由 ImagePreviewer 负责释放。 ```csharp public IImagePreviewSource SecurePreviewSource { get; } = new StreamImagePreviewSource( openReadAsync: cancellationToken => { Stream stream = File.OpenRead("/secure/photos/invoice.png"); return new ValueTask(stream); }, displayName: "invoice.png", contentType: "image/png", identity: "/secure/photos/invoice.png"); ``` ## Upload 组合式触发器迁移 `6.0.8` 中 Upload 根控件只负责文件状态、队列、Form 值和生命周期;选择文件、选择目录、拖拽区由可组合控件承担。 ### 6.0.7 写法 ```xml ``` ### 6.0.8 写法 ```csharp using AtomUI.Desktop.Controls; using System.Collections.ObjectModel; public ObservableCollection Attachments { get; } = []; public IFileUploadTransport UploadTransport { get; } = new MyUploadTransport(); ``` ```xml ``` ### 拖拽上传 ```xml ``` ### Form 值投影 `FileValueMode` 控制 Upload 写入 Form 的值: ```xml ``` ## OtpLineEdit 新增控件 `OtpLineEdit` 用单一 `Text` 表达完整验证码;cell、separator 和 mask 只影响视觉。 ```xml ``` ```xml ``` ```csharp public string? Code { get; set; } ``` ## Form 和 DataValidationErrors `6.0.8` 中 Form validator 产生的错误会写入 Avalonia `DataValidationErrors`。如果已有 ViewModel 校验、binding 校验或业务层原生 validation error,AtomUI 控件会以原生 error 为最高优先级展示。 默认触发方式为 `OnChanged`;需要失焦后再验证时显式配置: ```xml ``` ## 默认双向绑定 多个选择和值语义属性现在默认使用 `BindingMode.TwoWay`。不再需要在常规场景中显式写 `Mode=TwoWay`: ```xml ``` 如果业务确实需要只读投影,仍可在绑定上显式设置 `Mode=OneWay`。 ## DataGrid 过滤模型 列过滤现在直接挂在列 API 上,过滤项来源和选中值可绑定: ```xml ``` 树形过滤使用 `FilterChildrenMemberPath`: ```xml ``` ## Select、ComboBox 和 Cascader 溢出提示 选中内容无法完整显示时,可以开启溢出 tooltip: ```xml ``` ## TabControl 和 TabStrip 拖动排序 ```xml Content 1 Content 2 Content 3 ``` `TabActivationTrigger="PointerReleased"` 是默认值,适合拖动排序场景;如果需要鼠标按下立即激活,可改为 `PointerPressed`。 ## Dialog 异步关闭校验 ```csharp await Dialog.ShowDialogAsync( new TextBlock { Text = "Close without saving?" }, options: new DialogOptions { Title = "Unsaved changes", BeforeCloseAsync = async context => { if (context.Reason == DialogCloseReason.Rejected) { return true; } return await ConfirmSaveAsync(); } }); ```