Skip to content

fix(ui): 修复窗口最小化后恢复时滚动位置偏移 [Claude-Opus-5.5] - #45

Merged
LuLu-ling merged 1 commit into
PCL-Community:devfrom
zhuzhi-09:fix/23-scroll-restore
Nov 16, 2026
Merged

LuLu-ling merged 1 commit into
PCL-Community:devfrom
zhuzhi-09:fix/23-scroll-restore

Conversation

@zhuzhi-09

@zhuzhi-09 zhuzhi-09 commented Nov 16, 2026 •

Copy link
Copy Markdown

变更说明 / Summary

窗口最小化后恢复(Windows 最小化 / 切屏、macOS 台前调度等)时,Avalonia 会在窗口重新激活时把焦点还给之前获得焦点的控件(WindowBase.HandleActivated → FocusManager.SetFocusScope),ScrollViewer 收到 GotFocus 后把该控件滚入视野。若该控件已经滚出可视区域,页面就会被拉回该控件处,表现为滚动位置偏移。

以“设置 → 启动”为例:进入页面后顶部的“默认实例隔离”下拉框(ComboArgumentIndieV2)获得焦点;滚到底部后最小化再恢复,焦点被还给这个下拉框,页面随之上移 132px。

MyScrollViewer 订阅所属窗口的 Activated 事件,在此期间标记为正在恢复焦点,OnGotFocus 不再触发滚入视野;标记通过 Dispatcher.UIThread.Post 在恢复焦点完成后清除。Tab 切换、点击和代码调用 Focus() 时的滚入视野行为不变。

关联 Issue / Related Issue

Closes #23

验证方式 / Verification

构建

  • .NET SDK 11.0.100-rc.3.26522.148,dotnet publish PCL.Launcher/PCL.Launcher.csproj -c Debug -r win-x64 --no-self-contained -p:Platform=x64 与 -r osx-arm64 -p:Platform=ARM64,均编译通过

定位

  • 在 MyScrollViewer 中临时加入日志(已移除,未包含在提交中),确认偏移发生在最小化时的窗口激活中:HandleActivated → GotFocus(ComboArgumentIndieV2) → Offset 变化 −132,Extent 与 Viewport 均未变化

运行测试

  • Windows 11 x64:进入“设置 → 启动”,滚动到底部,最小化后恢复
    • 修复前:页面上移 132px
    • 修复后:滚动位置保持不变
  • macOS(Apple Silicon):手动按同样步骤测试,修复后未再出现偏移
  • 附图:
i23_compare

未覆盖

  • Linux 未测试
  • macOS 台前调度场景未单独测试

AI 使用情况 / Generative Artificial Intelligence Usage

  • 使用情况 / Usage:实质性使用 / Substantial
  • 使用工具及模型 / Tools and models:Claude Code(Claude Opus 5.5)
  • 使用目的 / Purpose:复现问题、定位原因、编写修复、编译测试、撰写提交信息与 PR 描述
  • 涉及范围 / Scope:PCL.Launcher/UI/Controls/Containers/MyScrollViewer.cs
  • 人工审查与验证 / Human review and verification:本人在 macOS 上手动验证了修复效果,并核对了 Windows 上修复前后的截图

提交前检查 / Checklist

  • 我已阅读并遵守 技术规范 和 生成式人工智能使用方针。/ I have read and followed the Technical Guidelines and the Generative Artificial Intelligence Usage Policy.
  • 我能解释本次修改的全部内容,包括关键逻辑、异常处理和已知限制。/ I can explain all changes, including key logic, error handling, and known limitations.
  • 我确认未伪造日志、测试结果、基准数据或其他证据。/ I confirm that no logs, test results, benchmarks, or other evidence have been fabricated.
  • 本次提交不包含与修改无关的文件变更,也未提交临时文件或构建产物。/ The PR contains no unrelated changes, temporary files, or build artifacts.
  • 所有提交均已签名,且提交信息符合提交信息规范。/ All commits are signed and follow the commit message convention.
  • 我确认 PR 描述由本人撰写,未直接提交未经核实的 AI 生成内容。/ I confirm that I wrote this PR description myself and have not submitted unverified AI-generated content.

此PR由claude编写,本人已阅读并确认。

窗口重新激活时,Avalonia 会把焦点还给之前获得焦点的控件,
ScrollViewer 随即把该控件滚入视野。若该控件已滚出可视区域
(例如设置页顶部的下拉框),恢复窗口后页面会被拉回该控件处。

MyScrollViewer 在所属窗口 Activated 时标记正在恢复焦点,
期间获得焦点不再触发滚入视野;标记在当前调度结束后清除,
Tab 切换、点击和代码调用 Focus() 的行为不变。

Closes PCL-Community#23
@LuLu-ling
LuLu-ling merged commit e2a942d into PCL-Community:dev Nov 16, 2026
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C#]: 最小化启动器后重新打开可能会使滚动进度偏移

2 participants