Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning content in a WPF Viewbox

Tags:

c#

wpf

xaml

viewbox

I have a Viewbox with Stretch=Uniform in order to not distort the content. However, when the frame window is wider or taller than the content, the Viewbox content is always centered.

I cannot seem to find any content alignment options on the Viewbox. Is there a way to do this?

like image 584
Jeff B Avatar asked Dec 04 '08 21:12

Jeff B


2 Answers

Try VerticalAlignment="Top" and HorizontalAlignment="Left" on your viewbox. It will cause it to be anchored to the top and left side.

<Grid>
    <Viewbox VerticalAlignment="Top" HorizontalAlignment="Left">
    ...
    </Viewbox>
</Grid>

If you want it to completely fill (but keep it uniform) you can use Stretch="UniformToFill"

like image 57
John Z Avatar answered Nov 20 '22 13:11

John Z


According to MSDN the Viewbox is used to stretch the child elements. Since the child elements would be stretched, you would have to set the content alignment of the children.

You may want to look at this for more information on the Viewbox: How do I keep aspect ratio on scalable, scrollable content in WPF?

like image 1
a_hardin Avatar answered Nov 20 '22 15:11

a_hardin