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>
This commit is contained in:
Julian LechnerandClaude Opus 5.5 committed 2026-11-18 10:14:24 +01:00
1 parent b6c33780c3
commit df09ddeaa9
8 files changed
+69 -185

No files matched your search

+13 -46
View File
@@ -4,61 +4,28 @@ Apply these rules when writing view models, data bindings, property notification
## 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.
* Keep view models to presentation state and commands; keep domain logic in services.
* Never reference `Window`, `UserControl`, `DispatcherObject`, or other visual tree elements from view models.
* Open dialogs, message boxes, and navigation through application services, not directly from view models.
* Keep dependencies minimal, derive state instead of duplicating it, and 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.
* Prefer data binding over manual UI synchronization, with strongly typed properties and short, stable binding paths.
* Use `OneWay` unless the UI must modify the source, and avoid `UpdateSourceTrigger=PropertyChanged` when the update is expensive.
* Treat binding errors as defects: check the debugger output or XAML binding failure diagnostics after UI changes, and use `FallbackValue` and `TargetNullValue` only for intended behavior, not to hide broken bindings.
* Expose correctly shaped state from the view model instead of converter or `MultiBinding` logic, and never put business logic in 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.
* Raise `PropertyChanged` only when a value actually changes, and keep dependent notifications explicit instead of hidden chains.
* Use the project's MVVM library for notifications. Without one, prefer CommunityToolkit.Mvvm source generators (`[ObservableProperty]`, `[RelayCommand]`; on partial properties from 8.4.1, which requires 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.
* Use dependency properties only when the WPF property system is required, not as a replacement for CLR properties.
* Keep metadata and property-changed callbacks lightweight and free of hidden side effects, coerce or validate only when the control contract requires it, and never use mutable default values in 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.
* Use attached properties and behaviors for reusable view-specific behavior, never to hide business logic. Keep them focused, avoid global state in them, and clean up event handlers when they detach.