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:
1 parent
b6c33780c3
commit
df09ddeaa9
8 files changed
+69
-185
No files matched your search
@@ -4,28 +4,16 @@ Apply these rules when implementing commands, async operations, UI-thread work,
|
||||
|
||||
## Commands
|
||||
|
||||
* Prefer commands over click handlers for ViewModel-driven actions.
|
||||
* Keep command execution focused.
|
||||
* Avoid putting large workflows directly inside command implementations.
|
||||
* Keep `CanExecute` logic cheap.
|
||||
* Refresh command availability only when relevant state changes.
|
||||
* Avoid command implementations with hidden side effects.
|
||||
* Prefer commands over click handlers for view-model actions. Keep command bodies focused, delegate large workflows to services, keep `CanExecute` cheap, and refresh it only when relevant state changes.
|
||||
* Implement async commands with the project's MVVM library (for example CommunityToolkit.Mvvm `AsyncRelayCommand` or `[RelayCommand]`): disable re-entry unless concurrent runs are intended, expose cancellation for long operations, and surface failures to the user.
|
||||
* Never use `async void` except for true event handlers.
|
||||
* Use `async void` only for true event handlers, and wrap their bodies in `try`/`catch` (see the C# async rule).
|
||||
|
||||
## Async and Threading
|
||||
|
||||
* Keep async operations asynchronous throughout the call chain.
|
||||
* Avoid `.Result`, `.Wait()` and other synchronous blocking of async work.
|
||||
* Do not block the UI thread.
|
||||
* Run I/O asynchronously.
|
||||
* Move expensive CPU work off the UI thread only when necessary.
|
||||
* Follow the C# async rule; in WPF, never block the UI thread, run I/O asynchronously, and move measured CPU-heavy work off it.
|
||||
* Let `await` resume on the UI thread in view models instead of calling the Dispatcher. When marshaling is unavoidable, inject a dispatcher abstraction; never use `Application.Current.Dispatcher` in view models, which breaks testing without a UI thread.
|
||||
* Do not use the Dispatcher to hide incorrect threading design.
|
||||
* Support `CancellationToken` for cancellable long-running operations.
|
||||
* Cancel obsolete work when views or selections change.
|
||||
* Prevent race conditions caused by overlapping async operations.
|
||||
* Handle exceptions from background operations explicitly.
|
||||
* Cancel obsolete work when views or selections change, prevent overlapping operations from overwriting newer results, and handle exceptions from background work explicitly.
|
||||
|
||||
## UI Thread
|
||||
|
||||
@@ -35,10 +23,5 @@ Apply these rules when implementing commands, async operations, UI-thread work,
|
||||
|
||||
## Events
|
||||
|
||||
* Avoid unnecessary event subscriptions.
|
||||
* Unsubscribe from long-lived publishers when required.
|
||||
* Prevent memory leaks from event handlers.
|
||||
* Use `WeakEventManager<TSource, TEventArgs>` where the publisher lives significantly longer than the subscriber.
|
||||
* Keep event handlers small.
|
||||
* Do not use events as hidden global communication channels.
|
||||
* Avoid excessive event chaining.
|
||||
* Unsubscribe from long-lived publishers, or use `WeakEventManager<TSource, TEventArgs>` where the publisher lives much longer than the subscriber, to prevent leaks.
|
||||
* Keep event handlers small, and do not use events as hidden global communication channels or long chains.
|
||||
Reference in new issue
Block a user