Skip to main content
Version: 0.10.x

Viewbox

The Viewbox is a decorator control which scales its child. It can be used to scale its child to fit the available space.

The Viewbox gives its child infinite space in the measure phase. It will constrain either or both sides when arranging it. This depends on the value of the Stretch.

To restrict scaling direction one can use StretchDirection which can prevent up or down scaling.

<!-- Ellipse will occupy 50x50px space -->
<Ellipse Width="50" Height="50" Fill="CornflowerBlue" />

<!-- Ellipse will be scaled to occupy 300x300px space -->
<Viewbox Stretch="Uniform" Width="300" Height="300">
<Ellipse Width="50" Height="50" Fill="CornflowerBlue" />
</Viewbox>

Common Properties

PropertyTypeDefaultDescription
StretchStretchUniformDetermines how child fits into the available space
StretchDirectionStretchDirectionBothDetermines in what direction child will be scaled

Examples

Stretch
Uniform

UniformToFill

Fill

None

StretchDirection
Both
UpOnly

DownOnly

Pseudoclasses

None

Reference

Viewbox

Source code

Viewbox.cs