Skip to content

feat(extract): link XAML ViewModels and bindings - #1473

Closed
MikeKatsoulakis wants to merge 1 commit into
Graphify-Labs:v8from
MikeKatsoulakis:feat-xaml-viewmodel-bindings
Closed

MikeKatsoulakis wants to merge 1 commit into
Graphify-Labs:v8from
MikeKatsoulakis:feat-xaml-viewmodel-bindings

Conversation

@MikeKatsoulakis

Copy link
Copy Markdown
Contributor

What

Adds deeper WPF/XAML graph extraction on top of the initial XAML support.

This branch resolves XAML views to ViewModels from:

  • explicit <Window.DataContext><vm:MainViewModel /></Window.DataContext> / equivalent DataContext elements
  • design-time d:DataContext="{d:DesignInstance Type=...}"
  • naming conventions like SettingsView -> SettingsViewModel
  • Prism ViewModelLocator.AutoWireViewModel="True"

It also extracts richer binding references:

  • binding paths: {Binding User.Name}, {Binding Path=Order.Total}
  • commands: Command="{Binding SaveCommand}"
  • converters: Converter={StaticResource MoneyConverter}
  • direct <Binding Path="..." Converter="..." />

This adds support for common WPF MVVM patterns/frameworks:

  • plain WPF/MVVM DataContext patterns
  • design-time ViewModel hints
  • naming-convention ViewModel lookup
  • Prism AutoWire ViewModel conventions
  • CommunityToolkit.Mvvm generated members:
    • [ObservableProperty] private string userName; -> inferred UserName
    • [ObservableProperty] on the line above a field -> inferred generated property
    • [RelayCommand] private void Save() -> inferred SaveCommand
    • [RelayCommand] private async Task SaveAsync() -> inferred SaveCommand
  • EventToCommand-style command binding via InvokeCommandAction Command="{Binding SaveCommand}"

Inference is conservative:

  • only links a ViewModel when exactly one matching C# class is found
  • skips ambiguous ViewModel candidates
  • marks convention/generated links as INFERRED
  • does not infer commands from plain methods without [RelayCommand]
  • respects .gitignore / .graphifyignore
  • keeps ViewModel .cs scans inside the active extraction root

Why

WPF apps often split UI behavior across .xaml, .xaml.cs, ViewModels, binding paths, commands, converters, and MVVM framework conventions. Without these links, graphify can see the files but misses the relationships that explain how UI flows into application code.

This makes WPF/XAML more useful in the graph:

  • views connect to their real ViewModels
  • buttons/commands connect to command members
  • Toolkit-generated properties and commands are represented
  • Prism AutoWire conventions are understood
  • bindings and converters become searchable graph references

Scope

This is WPF/XAML-oriented support.

WinUI, MAUI, Avalonia, and other XAML-based stacks may get some collateral benefit where their syntax overlaps with WPF/XAML, but they are not the focus of this PR or the previous WPF PR. I am not a WinUI/MAUI expert, so I would not want to claim direct support unless someone specifically asks for it and provides real examples.

If there are issues, bugs, or additions needed for further WPF support, please tag me: @MikeKatsoulakis.

Tests

Added focused fixtures and tests for:

  • explicit ViewModel DataContext
  • design-time ViewModel DataContext
  • naming inference
  • Prism AutoWire true/false behavior
  • ambiguous ViewModel candidates
  • CommunityToolkit generated members, including same-line and next-line attributes
  • EventToCommand command bindings
  • binding paths, converters, and commands
  • extraction ID remapping
  • .graphifyignore behavior
  • cache-root scan boundary behavior
  • false-positive cases for Toolkit comments and non-event XAML attributes

Validated with:

uv run --frozen pytest tests/test_dotnet.py -q
uv run --frozen pytest tests/test_languages.py -k "sln or csproj or xaml or razor" -q
uv run --frozen ruff check graphify\extract.py tests\test_dotnet.py
git diff --check

Local full-suite note: uv run --frozen pytest tests/ -q still fails on this Windows checkout with existing platform/path/skillgen baseline failures; the targeted .NET/XAML checks above pass.

Security Review

A security pass found that ViewModel lookup could scan .cs files outside the requested extraction boundary and repeat scans per XAML file. This branch fixes that by bounding lookup to the active extraction root, respecting ignore files, and caching the class scan during extraction.

No XML entity expansion, regex DoS, or graph-label injection issue was found.

@MikeKatsoulakis
MikeKatsoulakis marked this pull request as ready for review June 26, 2026 07:51
safishamsi pushed a commit that referenced this pull request Jun 26, 2026
…rences (#1473)

Builds on the initial XAML support (#1460). Resolves a view to its ViewModel from
an explicit <Window.DataContext><vm:MainViewModel/>, a design-time
d:DataContext="{d:DesignInstance Type=...}", the View->ViewModel naming
convention, or Prism ViewModelLocator.AutoWireViewModel="True". Resolution is
always against an actually-extracted C# class node, so a name matching no class
(or an ambiguous 2+) emits no edge -- explicit DataContext is EXTRACTED,
convention/Prism are INFERRED. Also extracts binding paths ({Binding User.Name},
Path=Order.Total), commands (Command="{Binding SaveCommand}"), converters, and
CommunityToolkit [ObservableProperty]/[RelayCommand] generated members.

The #1460 event-handler hardening is preserved unchanged: events still resolve
only to methods with a .NET (object sender, ...EventArgs e) signature, and the
free-form-attribute denylist still prevents values like Content="Save" from
fabricating event edges (both regression tests still pass). ViewModel discovery is
bounded to the active extraction root.

Ported from PR #1473 by @MikeKatsoulakis (clean 3-way merge onto current v8).
Maintainer fix on top: the CommunityToolkit member reader now reads the
code-behind with errors="replace", so a non-UTF8 ViewModel .cs can't raise
UnicodeDecodeError and abort extract_xaml (matches every other reader in the
module). Added a regression test for that case.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Thanks @MikeKatsoulakis — strong follow-up to #1460. The ViewModel resolution is exactly the kind of careful work I hoped for: it resolves against actually-extracted C# class nodes and refuses to emit an edge when the name matches no class or an ambiguous 2+, with EXTRACTED for explicit DataContext and INFERRED for naming/Prism conventions. The binding-path/command/converter extraction and CommunityToolkit member synthesis are clean, and — importantly — the #1460 event-handler signature gate and the free-form-attribute denylist are preserved unchanged (both regression tests still pass).

Landed on v8 in 905e0a7 with your authorship preserved (clean 3-way merge onto current v8). One maintainer fix on top: the CommunityToolkit member reader now reads the code-behind with errors="replace", so a non-UTF8 ViewModel .cs can't raise UnicodeDecodeError and abort extract_xaml (every other reader in the module already does this). Added a regression test. Verified end-to-end: explicit DataContext resolves to the real VM (EXTRACTED) and the View->ViewModel convention resolves (INFERRED). Full suite 2451 passed. Closing as merged-by-port — thanks!

@safishamsi safishamsi closed this Jun 26, 2026
safishamsi added a commit that referenced this pull request Jun 27, 2026
Dates the 0.8.50 CHANGELOG and bumps the version. Highlights: WPF/XAML extraction
+ ViewModel/binding links (#1460/#1473), Objective-C relationship fixes (#1475),
.vue SFC grammar fix (#1468), Metal shader indexing (#1480), Java field/annotation
references (#1485/#1487), portable wiki links (#1444), *_BASE_URL backend overrides
(#1458), non-streaming OpenAI-compatible calls (#1223), reflect --if-stale sidecar
freshness (#1470), label --missing-only (#1481), canvas grid + case-fold dedup
(#1452/#1453), the Read|Glob hook extension fix (#1463), and the no-API-key skill
clarification (#1461).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
…rences (Graphify-Labs#1473)

Builds on the initial XAML support (Graphify-Labs#1460). Resolves a view to its ViewModel from
an explicit <Window.DataContext><vm:MainViewModel/>, a design-time
d:DataContext="{d:DesignInstance Type=...}", the View->ViewModel naming
convention, or Prism ViewModelLocator.AutoWireViewModel="True". Resolution is
always against an actually-extracted C# class node, so a name matching no class
(or an ambiguous 2+) emits no edge -- explicit DataContext is EXTRACTED,
convention/Prism are INFERRED. Also extracts binding paths ({Binding User.Name},
Path=Order.Total), commands (Command="{Binding SaveCommand}"), converters, and
CommunityToolkit [ObservableProperty]/[RelayCommand] generated members.

The Graphify-Labs#1460 event-handler hardening is preserved unchanged: events still resolve
only to methods with a .NET (object sender, ...EventArgs e) signature, and the
free-form-attribute denylist still prevents values like Content="Save" from
fabricating event edges (both regression tests still pass). ViewModel discovery is
bounded to the active extraction root.

Ported from PR Graphify-Labs#1473 by @MikeKatsoulakis (clean 3-way merge onto current v8).
Maintainer fix on top: the CommunityToolkit member reader now reads the
code-behind with errors="replace", so a non-UTF8 ViewModel .cs can't raise
UnicodeDecodeError and abort extract_xaml (matches every other reader in the
module). Added a regression test for that case.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
Dates the 0.8.50 CHANGELOG and bumps the version. Highlights: WPF/XAML extraction
+ ViewModel/binding links (Graphify-Labs#1460/Graphify-Labs#1473), Objective-C relationship fixes (Graphify-Labs#1475),
.vue SFC grammar fix (Graphify-Labs#1468), Metal shader indexing (Graphify-Labs#1480), Java field/annotation
references (Graphify-Labs#1485/Graphify-Labs#1487), portable wiki links (Graphify-Labs#1444), *_BASE_URL backend overrides
(Graphify-Labs#1458), non-streaming OpenAI-compatible calls (Graphify-Labs#1223), reflect --if-stale sidecar
freshness (Graphify-Labs#1470), label --missing-only (Graphify-Labs#1481), canvas grid + case-fold dedup
(Graphify-Labs#1452/Graphify-Labs#1453), the Read|Glob hook extension fix (Graphify-Labs#1463), and the no-API-key skill
clarification (Graphify-Labs#1461).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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