Files
MyAiConfiguration/shared/rules/wpf/references/mvvm-and-binding.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

3.2 KiB

WPF MVVM, Binding, and Properties

Apply these rules when writing view models, data bindings, property notifications, dependency properties, or behaviors.

MVVM

  • Keep ViewModels focused on presentation state and commands.
  • Do not put UI element references into ViewModels.
  • Do not access Window, UserControl, DispatcherObject or visual tree elements from ViewModels.
  • Avoid direct navigation, dialogs or message boxes from ViewModels without an abstraction when testability matters.
  • Prefer explicit application services for navigation, dialogs and external interactions.
  • Keep domain logic outside ViewModels.
  • Do not use ViewModels as general-purpose service containers.
  • Keep ViewModel dependencies minimal.
  • Prefer immutable or readonly state where practical.
  • Avoid duplicated derived state.
  • Keep state transitions predictable.

Data Binding

  • Prefer data binding over manual UI synchronization.
  • Use strongly typed properties.
  • Use appropriate binding modes.
  • Prefer OneWay when two-way updates are not required.
  • Use TwoWay only when the UI must modify the source.
  • Avoid unnecessary UpdateSourceTrigger=PropertyChanged for expensive operations.
  • Keep binding paths simple and stable.
  • Avoid deeply nested binding paths.
  • Do not hide broken bindings.
  • Treat binding errors as real defects.
  • Use FallbackValue and TargetNullValue only when they reflect intended behavior.
  • Avoid excessive converters.
  • Prefer exposing correctly shaped state from the ViewModel over complex converter logic.
  • Avoid MultiBinding when simpler state modeling is clearer.
  • Do not put business logic into converters.

Property Change Notifications

  • Implement property change notifications consistently.
  • Avoid raising PropertyChanged unnecessarily.
  • Raise notifications only when values actually change.
  • Keep dependent property notifications explicit.
  • Avoid hidden notification chains that are difficult to reason about.
  • Prefer reusable base implementations only when they reduce duplication without obscuring behavior.
  • Use the project's MVVM library for notifications. Without one, prefer CommunityToolkit.Mvvm source generators ([ObservableProperty], [RelayCommand]; on partial properties from 8.4.1 with C# 14) or a base class using [CallerMemberName]. Avoid reflection- or proxy-based notification frameworks unless the project already uses one.

Dependency Properties

  • Use dependency properties only when WPF property-system behavior is required.
  • Do not use dependency properties as a replacement for normal CLR properties.
  • Keep metadata and callbacks lightweight.
  • Avoid expensive work in property-changed callbacks.
  • Avoid callbacks with hidden side effects.
  • Validate or coerce values only when the control contract requires it.
  • Do not expose mutable default values in dependency property metadata.

Attached Properties and Behaviors

  • Use attached properties and behaviors for reusable view-specific behavior.
  • Do not use them to hide business logic.
  • Keep behaviors focused and predictable.
  • Clean up event handlers when behaviors are detached.
  • Avoid global attached-property state.
  • Prefer explicit behavior over complex XAML hacks.