Derived dimensions
A Thickness or a CornerRadius declared in a ResourceDictionary is baked at parse time. Its Left/Top/Right/Bottom (or TopLeft/TopRight/…) are plain CLR properties, not dependency properties, so they can only be fed with StaticResource and never follow a later change of the scalar they were built from:
<!-- Baked at load: editing BorderWidth at runtime does nothing here -->
<system:Double x:Key="BorderWidth">1</system:Double>
<Thickness x:Key="MenuBorderThickness" Right="{StaticResource BorderWidth}" />
Derive.BorderThickness, Derive.CornerRadius and Derive.Margin build the value on the element instead, from a real DynamicResource. A scalar edited at runtime — by the theme customizer, for instance — flows straight through, and no derived resource key has to be declared or re-pushed by hand.
Point it at the key of the category the element belongs to (DisplayThickness, DisplayRadius, InputRadius, ActionRadius…, see Design tokens), so the part follows the rest of the control when a theme reshapes that category. The global Thickness and Radius are for an app’s own layout.
Factors
Each of the three properties has a matching factor, a Thickness (or a CornerRadius) whose components multiply the derived value side by side:
| Factor component | Result |
|---|---|
0 | The side or corner is dropped |
1 | It is kept as is |
| anything else | It is scaled — 2 for a doubled margin, 0.5 for a halved radius |
The default is 1,1,1,1, so the derived value is applied whole.
Derive.BorderThickness
Point Derive.BorderThickness at a resource key and pick the sides with Derive.BorderThicknessFactor, in the usual Left,Top,Right,Bottom order.
<!-- Right edge only, following Dimensions.DisplayThickness live -->
<Border toolkit:Derive.BorderThickness="{x:Static joufflu:Dimensions.DisplayThickness}"
toolkit:Derive.BorderThicknessFactor="0,0,1,0" />
<!-- Open at the bottom, with a doubled top edge -->
<Border toolkit:Derive.BorderThickness="{x:Static joufflu:Dimensions.DisplayThickness}"
toolkit:Derive.BorderThicknessFactor="1,2,1,0" />
Both properties work in a Style setter, so a style can derive its border without a keyed Thickness:
<Style x:Key="SidePanel" TargetType="Border">
<Setter Property="toolkit:Derive.BorderThickness" Value="{x:Static joufflu:Dimensions.DisplayThickness}" />
<Setter Property="toolkit:Derive.BorderThicknessFactor" Value="0,0,1,0" />
</Style>
In a style, the fed property stops being overridable. The derived value is pushed with
SetCurrentValue, which outranks a style setter — and even a local value; only an animation or a template trigger still takes over. So do not also set the property it feeds (hereBorderThickness) in the same style, move anyStyle.Triggersthat change it onto theDeriveproperty, and expect that a consumer can no longer override it.Derivefits a value the control owns — aBorderinside a template. When the fed property has to stay overridable — a text input’sPadding, say — give it a plain keyed default (Dimensions.InputPadding*) instead.
Derive.CornerRadius
Same shape, with Derive.CornerRadiusFactor in the TopLeft,TopRight,BottomRight,BottomLeft order.
<!-- Top corners only, matching the border it sits in -->
<Border toolkit:Derive.CornerRadius="{x:Static joufflu:Dimensions.DisplayRadius}"
toolkit:Derive.CornerRadiusFactor="1,1,0,0" />
Derive.Margin
Same shape again, on any FrameworkElement, with Derive.MarginFactor.
<!-- Spaced everywhere but the top -->
<Border toolkit:Derive.Margin="{x:Static joufflu:Dimensions.Spacing}"
toolkit:Derive.MarginFactor="1,0,1,1" />
Notes
- The source resource may be a
Thickness/CornerRadius(every Joufflu shape key is one), whose own sides are then scaled, or adouble, spread over every side or corner before scaling. - Pass the resource key (
{x:Static …}):Derivefollows the resource itself. AThickness,CornerRadiusordoublevalue is taken as is instead, so inside a templatetoolkit:Derive.Margin="{TemplateBinding Padding}"scales the control’s own padding. Derive.BorderThicknessapplies toBorderand to anyControl;Derive.CornerRadiusapplies toBorder;Derive.Marginto anyFrameworkElement. Anything else throws.