Skip to content

Fix discovery of detached WPF popup presentation roots - #26

Closed
mmair07 wants to merge 1 commit into
faze79:mainfrom
mmair07:fix/discover-detached-wpf-popup-roots
Closed

mmair07 wants to merge 1 commit into
faze79:mainfrom
mmair07:fix/discover-detached-wpf-popup-roots

Conversation

@mmair07

@mmair07 mmair07 commented Nov 18, 2026

Copy link
Copy Markdown

Problem

Global element discovery starts from Application.Current.Windows. WPF ContextMenu, Popup, dropdown and ToolTip content can live in separate PresentationSource roots without being reachable through a window's visual tree. Dynamically created context menus are a standard reproduction; no custom controls or application-specific metadata are needed.

Changes

  • Include active PresentationSource roots on the calling Inspector dispatcher, retaining application windows for existing hidden-window lookup semantics.
  • Work without an Application object when collecting presentation roots.
  • Skip disposed sources and sources belonging to another UI dispatcher.
  • Traverse all global find roots with one visited set so overlapping roots do not duplicate results or consume the result limit.
  • Route both regular and deep global find queries through that traversal; preserve the deep-search truncation flag.
  • Reuse the expanded roots for existing wait, AutomationId and recorded-workflow resolution paths.
  • Keep explicit root_handle searches restricted to their existing subtree.
  • Document scope, limitations and the fact that discovery does not open menus or realize virtualized items.

Regression coverage

Seven new cases cover dynamically created context menus, matching by text/type/AutomationId, wait lookup, stable selectors, asynchronous close, overlapping roots/result limits, standalone/disposed HwndSource roots, foreign dispatchers, ComboBox dropdowns, ToolTips and ambiguous IDs across detached roots.

The original root collector returned no matching dynamically created context-menu content and did not discover standalone HwndSource roots; the new tests reproduce these failures before the fix.

Validation

  • dotnet build src\WpfVisualTreeMcp.Server\WpfVisualTreeMcp.Server.csproj
    Passed, 0 warnings / 0 errors on the final incremental build; Inspector payloads built for net472, net48 and net8.0-windows.
  • dotnet test tests\WpfVisualTreeMcp.IntegrationTests\WpfVisualTreeMcp.IntegrationTests.csproj --no-build
    45 passed, 1 skipped. The external runtime/architecture/injection matrix requires its own configured runner and was not executed.
  • dotnet test tests\WpfVisualTreeMcp.Tests\WpfVisualTreeMcp.Tests.csproj
    262 passed.
  • git diff --check
    Passed.

Include current-dispatcher presentation sources and deduplicate overlapping global query roots. Preserve explicit subtree scope and add generic popup, dropdown, tooltip, ambiguity and dispatcher regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mmair07

mmair07 commented Nov 18, 2026

Copy link
Copy Markdown
Author

Closing this duplicate in favor of the earlier upstream popup/submenu fix in #25. I locally combined #25 with the window/recording indicator from #24 and verified the popup/submenu discovery against our FIM simulation; no device command was executed. Thank you for reviewing the overlap.

@mmair07 mmair07 closed this Nov 18, 2026
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.

2 participants