Search code examples
c#wpfxamlviewbox

Aligning content in a WPF 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?


Solution

  • 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"