#1,064 – Limiting ViewBox to Scale in Just One Direction
May 2, 2014 1 Comment
When you use a ViewBox to scale some content, by default it scales the content either larger or smaller than the default size of the content.
You can change this behavior by setting the StretchDirection of the ViewBox to one of the following values:
- Both (the default) – allow scaling both up and down, relative to the default size of the content
- UpOnly – Only allow scaling larger than default size of content
- DownOnly – Only allow scaling smaller than default size of content
If you make the ViewBox a size at which scaling of the content is not allowed, the content will be clipped or whitespace will be added.
<Viewbox StretchDirection="UpOnly"> <Canvas Background="Bisque" Width="200" Height="100"> <Line X1="5" Y1="5" X2="195" Y2="95" Stroke="Black"/> <Label Canvas.Left="80" Canvas.Top="5" Content="Howdy"/> <Ellipse Height="30" Width="50" Stroke="Blue" StrokeThickness="2" Canvas.Left="140" Canvas.Top="5"/> </Canvas> </Viewbox>
Pingback: Dew Drop – May 2, 2014 (#1768) | Morning Dew