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,42 +4,22 @@ Apply these rules when binding collections, writing XAML, building layouts, or r
|
||||
|
||||
## 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 `ObservableCollection<T>` only when bindings need change notifications; use `List<T>` or other suitable collections for 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.
|
||||
* Expose 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.
|
||||
* Split large views into focused controls, and use resources and styles for repeated values instead of inline styling or magic numbers.
|
||||
* Choose controls by meaning (a `Button` for actions, not a styled `Border` with a click handler), and keep panels and visual trees shallow.
|
||||
* Prefer simple state in the view model over complex triggers and XAML tricks that hide behavior.
|
||||
|
||||
## 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.
|
||||
* Prefer `Grid` with `Auto` and `*` sizing for structured layouts; use `StackPanel` only where its unbounded stacking is intended, and avoid fixed sizes unless the design requires them.
|
||||
* Avoid layouts that cause repeated measure and arrange passes, and large visual trees inside scrolling containers (see the virtualization section).
|
||||
|
||||
## Virtualization
|
||||
|
||||
|
||||
Reference in new issue
Block a user