Topic Author
Posts: 13
Joined: 30 Nov 2017, 13:34

Viewbox and custom controls?

13 May 2022, 23:19

Is a Viewbox unable to scale a custom control based on the Image control?
<Viewbox Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Uniform">
	<local:SceneView x:Name="SceneView" Focusable="True"/>
The target control is around 1200x500 and the custom control is 1280x720. The control is stretched horizontally, and shrunk vertically to fill the space. I want to maintain the aspect ratio, while filling the space with the entire image visible.

The problem seem to be something with the grid row and column defines.
I set my rows as:
<RowDefinition Height="1*"/>
<RowDefinition Height="540"/>
<RowDefinition Height="1*"/>
and within the center row, I set my columns as:
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="960"/>
<ColumnDefinition Width="1*"/>
I get a 1085x540 center cell. Which screws up the aspect ratio.

It seems the only option is to hard code the left and right column widths.
User avatar
Site Admin
Posts: 2536
Joined: 22 Dec 2011, 19:20

Re: Viewbox and custom controls?

16 May 2022, 18:39

If you want to keep the aspect ratio of a 16:9 viewbox inside a 1200x500 container, setting the Stretch to Uniform will leave margins to the left and right, and setting it to UniformToFill will fill the entire container but not all the contents (image) will be visible.

What exactly is what you want to achieve?

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests