Files
Julian LechnerandClaude Opus 5.5 df09ddeaa9 docs(rules): add WPF accessibility and theming, trim WPF rules
A new WPF topic rule covers accessibility (AutomationProperties names
and help text, keyboard access, visible focus, high contrast through
SystemColors, automation peers for custom controls), DPI scaling in
device-independent units with tests across scale factors and monitors,
and the Fluent theme through ThemeMode on .NET 9 and later.

The existing WPF rules lose about a quarter of their size by merging
one-line generic bullets that the C# and shared rules already cover,
while keeping the WPF-specific pitfalls. Duplicate async void and
binding error guidance is merged, client secret handling defers to the
client app security rule, the architecture rule asks to check .NET
Framework versus .NET before using newer APIs, and the CommunityToolkit
note states that partial properties require C# 14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 10:14:24 +01:00

38 lines
1.8 KiB
Markdown

# WPF Resources, Windows, and Lifecycle
Apply these rules when managing resources and styles, windows and dialogs, navigation, memory, or images in WPF.
## Resources and Styles
* Use shared resources for repeated styles, brushes, templates, and dimensions, in focused dictionaries at feature level unless truly global; avoid hardcoded colors and sizes when resources exist.
* Use `StaticResource` by default and `DynamicResource` only where runtime replacement is required, such as theme switching.
## Windows and Dialogs
* Keep window lifecycle and `Owner` relationships explicit, avoid duplicate or hidden windows kept alive without reason, and set `ShutdownMode` deliberately instead of relying on accidental window lifetime.
* Show dialogs through the dialog service described in the MVVM rule.
## Navigation
* Keep navigation state and history explicit, map view models to views without service locators, and release navigation targets that are no longer needed.
## Memory Management
* Watch for memory leaks caused by:
* Event subscriptions
* Timers
* Static references
* Long-lived services
* Cached views
* Closures
* Collection views
* Binding-related references: binding to a CLR property of a source that does not implement `INotifyPropertyChanged` keeps the source alive; bind only to `INotifyPropertyChanged` or dependency-property sources.
* Dispose resources, stop timers and background work, and release closed windows, unloaded views, and visual element references. Profile memory when a long-running app keeps growing.
## Images and Media
* Decode images at display size with `BitmapImage.DecodePixelWidth` or `DecodePixelHeight`.
* Load file-based images with `BitmapCacheOption.OnLoad` and close the stream, so the file is not locked.
* Call `Freeze()` on immutable bitmaps and brushes, and cache images only with a clear memory limit.