Files
MyAiConfiguration/shared/rules/wpf/references/collections-and-xaml.md
T
Julian LechnerandClaude Opus 5.5 6159c6373c
CI / CI configuration security checks (pull_request) Successful in 2s
CI / Capabilities and shell quality (pull_request) Successful in 15s
CI / Python tests and compilation (pull_request) Successful in 36s
CI / QMD unit tests (pull_request) Successful in 7s
CI / Build and inspect generated packages (pull_request) Successful in 16s
CI / Bash integration and installation guards (pull_request) Failing after 51s
CI / PowerShell tests on Ubuntu (pull_request) Failing after 1m45s
CI / Installed client configuration smoke tests (pull_request) Canceled after 1m24s
docs(rules): fix contradictions, update technical rules, enforce rule structure
- Resolve contradictions: authorization is never a skipped "boundary check";
  one browser token policy (BFF/HttpOnly cookies first, RFC 10017); one
  sanitizer-bypass rule; Angular responses are unknown until validated.
- Add security rules for AI/LLM integration and Java XXE, concrete crypto
  and password-hashing parameters, and RFC 8725 JWT validation.
- Update version-dependent guidance after checking official sources:
  Angular 22, TypeScript 6/7, Node 24+, .NET 10/C# 14, JDK 21-25, Spring
  Boot 4; add a Spring Boot and Spring Security topic.
- Give every rule a unique level-1 title and scope line, keep language
  security files to language specifics, and fix routing for inbound vs
  outbound HTTP, XML parsing, and WPF/Angular parent rules.
- Validate rule structure and routing in validate-config.py, with tests.
- Fix CI issues found by a local run: shellcheck directive order, pinned
  ruff rule set, Invoke-Python test mock, CRLF-tolerant package checks,
  Windows-only credential test, and refreshed prompt-budget baselines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 10:51:08 +01:00

2.7 KiB

WPF Collections, XAML, Layout, and Virtualization

Apply these rules when binding collections, writing XAML, building layouts, or rendering large lists.

Collections

  • Use ObservableCollection<T> only when collection change notifications are required.
  • Do not use ObservableCollection<T> as a general-purpose collection.
  • Use List<T> or other suitable collections for non-observable internal data.
  • Use incremental Add and Remove for small changes. For bulk changes, assign a new collection instance or raise a single Reset; never raise multi-item Add, Remove, or Replace notifications to WPF bindings, because ListCollectionView throws NotSupportedException for range actions.
  • Wrap sort and filter changes in ICollectionView.DeferRefresh().
  • Mutate bound collections on the UI thread. Use BindingOperations.EnableCollectionSynchronization only when off-thread mutation is unavoidable.
  • Avoid exposing mutable internal collections unnecessarily.
  • Prefer read-only views where consumers should not modify data.

XAML

  • Keep XAML readable and focused.
  • Avoid excessively large view files.
  • Split complex views into focused controls when it improves maintainability.
  • Use resources for repeated values and styles.
  • Avoid magic numbers in XAML.
  • Keep styles and templates consistent.
  • Avoid excessive inline styling.
  • Prefer reusable resources over duplicated markup.
  • Avoid deeply nested panels.
  • Keep visual trees as shallow as practical.
  • Use semantic control choices.
  • Avoid unnecessary containers.
  • Do not overuse triggers when simpler state representation is possible.
  • Keep templates understandable.
  • Avoid XAML tricks that make behavior hard to discover.

Layout

  • Prefer Grid for structured layouts.
  • Use StackPanel only where its layout behavior is actually appropriate.
  • Avoid unnecessary nested panels.
  • Avoid fixed sizes unless the design requires them.
  • Prefer responsive sizing with Auto and *.
  • Avoid layout configurations that cause excessive measure/arrange passes.
  • Be careful with large visual trees inside scrolling containers; see the virtualization section.

Virtualization

  • Keep UI virtualization enabled for large collections and use VirtualizingPanel.VirtualizationMode="Recycling".
  • These settings silently disable virtualization: ScrollViewer.CanContentScroll="False", grouping without VirtualizingPanel.IsVirtualizingWhenGrouping="True", a non-virtualizing ItemsPanel such as StackPanel or WrapPanel, and placing the list inside a ScrollViewer or StackPanel that gives it unlimited height.
  • Verify virtualization with large data sets, and use paging or incremental loading for very large ones.