question

BitSmithy-4663 avatar image
0 Votes"
BitSmithy-4663 asked NicoZhu-MSFT answered

GridView - Image fits allways to available space, but keeps proportions.

Hello,


I have a GridView with such definition:

 <GridView x:Name="grvImagesList" Grid.Row="1">
                 <GridView.ItemContainerStyle>
                     <Style TargetType="GridViewItem">
                         <Setter Property="Margin" Value="5"/>
                         <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                         <Setter Property="VerticalContentAlignment" Value="Stretch" />
    
                     </Style>
                 </GridView.ItemContainerStyle>
             </GridView>


It scales an image in such way that it covers all available space in width, and keeps image proportions, so sometime image is higher than available space in hight.

I need such set setting that It scales an image in such way that it covers all available space in width, and keeps image proportions, but if in result image is higher than available space in hight, it covers all available space in height and keeps image proportions (consequently image width is narrower than available space in width). So i need that image fits allways to available space, but keeps proportions.


How to do such settings? For this behavior ListView is acceptable but I prefer GridView.

windows-uwp
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What's the Stretch property of image you set, have you tried use UniformToFill for stretch property?

0 Votes 0 ·

In my case proper answer is Stretch.Uniform, but it very helped. Post it as answer.

1 Vote 1 ·

1 Answer

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered

Hello, Welcome to Micorosoft Q&A,

Image fits allways to available space, but keeps proportions.

You may refer to image Stretch property, derive from the document, you could try to use Uniform value, The content is resized to fit in the destination dimensions while it preserves its native aspect ratio.



If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.