Repository navigation
fix(ui): 修复窗口最小化后恢复时滚动位置偏移 [Claude-Opus-5.5] - #45
Merged
Merged
Conversation
窗口重新激活时,Avalonia 会把焦点还给之前获得焦点的控件, ScrollViewer 随即把该控件滚入视野。若该控件已滚出可视区域 (例如设置页顶部的下拉框),恢复窗口后页面会被拉回该控件处。 MyScrollViewer 在所属窗口 Activated 时标记正在恢复焦点, 期间获得焦点不再触发滚入视野;标记在当前调度结束后清除, Tab 切换、点击和代码调用 Focus() 的行为不变。 Closes PCL-Community#23
LuLu-ling
approved these changes
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明 / 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
构建
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均未变化运行测试
未覆盖
AI 使用情况 / Generative Artificial Intelligence Usage
PCL.Launcher/UI/Controls/Containers/MyScrollViewer.cs提交前检查 / Checklist
此PR由claude编写,本人已阅读并确认。