Skip to content

Label

Label derives from the native System.Windows.Controls.Label and resolves a string For id to a FrameworkElement by name-scope lookup, assigning the inherited Label.Target and AutomationProperties.LabeledBy on it. It also adds explicit click-to-focus and a double/triple-click text-selection-suppression guard from scratch, since WPF’s native Label.Target only drives access-key/mnemonic activation, not a plain mouse click the way the HTML for= attribute does in a browser.

xmlns:navius="clr-namespace:Navius.Wpf.Primitives.Controls;assembly=Navius.Wpf.Primitives"
<StackPanel>
<navius:NaviusLabel For="Email" Content="Email address" />
<TextBox x:Name="Email" />
</StackPanel>
Property Type Default From Description
For string? null NaviusLabel The name of the associated control, resolved via FindName walking up the logical/visual tree from the label. Resolution is retried on Loaded and re-attempted eagerly on property change.
Target FrameworkElement? null Label Native focus target. Assigned automatically once For resolves; can also be set directly for the native access-key/mnemonic activation path.
Content object - ContentControl Label caption content, inherited via Label.
Key Behavior
Access key (Alt + underlined character in Content) Native Label/AccessText mnemonic activation moves focus to Target; the default template preserves RecognizesAccessKey="True".

NaviusLabel ships no custom AutomationPeer and inherits WPF’s native LabelAutomationPeer. AutomationProperties.SetLabeledBy(resolved, this) is set on the resolved Target at the same time Target is assigned, preserving the DOM for=’s screen-reader label association. The unit suite (LabelTests) exercises For resolution and LabeledBy wiring, single-click focus forwarding, and double/triple-click suppression (e.ClickCount > 1).

  • For stays a plain string? dependency property rather than becoming a bound object reference: it resolves to a FrameworkElement via FindName, mirroring the DOM’s for= id lookup, rather than using WPF’s native Target object-reference pattern directly (though Target remains settable for consumers who prefer it).
  • Click-to-focus and the double/triple-click text-selection-suppression guard are authored from scratch in an OnMouseDown override; the web component gets this behavior for free from the browser’s native for= handling, so there was no existing logic to translate.
  • The data-navius-label marker attribute has no WPF equivalent (no arbitrary data-* attribute concept) and was not replicated.
  • Attributes (CaptureUnmatchedValues passthrough on the web) is dropped globally across this batch of families; no extensibility story was built for arbitrary attribute forwarding.
  • M6 audit residual (not a defect): OnMouseDown fires for any mouse button, not just the left button. The web’s onmousedown is likewise button-agnostic, so this is arguably parity, but right-click focus-forwarding was not evaluated against AT expectations.

The Label Gallery page rendered at the pinned commit, in each theme.

Label Gallery page in the light theme

Label Gallery page in the dark theme

Label Gallery page in the high contrast theme