AspectRatio
Overview
Section titled “Overview”AspectRatio (NaviusAspectRatio) is a ContentControl overriding MeasureOverride to enforce a
fixed width:height ratio on its single child. It is a pure layout primitive: there is no CSS cascade
to replicate in WPF, so the child fills the computed box directly via the default
ContentPresenter rather than needing a separate inner element.
xmlns:navius="clr-namespace:Navius.Wpf.Primitives.Controls;assembly=Navius.Wpf.Primitives"
<navius:NaviusAspectRatio Ratio="1.7777"> <Image Source="banner.png" Stretch="UniformToFill" /></navius:NaviusAspectRatio>Properties
Section titled “Properties”| Property | Type | Default | From | Description |
|---|---|---|---|---|
Ratio |
double |
1.0 |
NaviusAspectRatio |
Desired width:height ratio. |
EffectiveRatio |
double |
computed | NaviusAspectRatio |
Read-only, not a DP. Ratio if positive, else 1.0. |
Content |
object |
- |
ContentControl |
The single child, filled into the computed box via the default ContentPresenter; there is no separate inner element the way the web has an inner <div>. |
UIA mechanism
Section titled “UIA mechanism”NaviusAspectRatio.cs has no OnCreateAutomationPeer() override; the web contract renders no ARIA
role or aria-* attribute either, so the parity doc’s own WPF strategy states no automation-peer
role mapping is needed beyond whatever default ContentControl supplies. The width-vs-height-driven
box math (NaviusAspectRatioMath.ComputeDesiredSize) is factored out into a pure static method and
unit-tested headless with plain [Fact]s, with no live Control/Application required.
Web deltas
Section titled “Web deltas”- The web’s padding-bottom percentage-hack (an outer/inner
<div>pair) has no WPF equivalent; this is a singleContentControloverridingMeasureOverride, computing the box directly rather than via a CSS trick. ForwardedAttributes/style-merge (the web’s “spread the consumer’s style, then append positioning last”) has no port: the single child simply fills the computed box via the defaultContentPresenter.- Width drives height whenever available width is finite (
Width / EffectiveRatio, the direct analog of the web’swidth:100%;padding-bottom:%hack). When width is infinite but height is finite, height instead drives width (Height * EffectiveRatio); when both are infinite, the box collapses to(0, 0). The web version is purely width-driven since a browser never presents an infinite-width layout, so the height-driven and both-infinite branches are WPF-specific additions with no web behavior to diverge from.
Captures
Section titled “Captures”The AspectRatio Gallery page rendered at the pinned commit, in each theme.


