网格中的人像图像被截断-WP8

本文关键字:-WP8 图像 网格 | 更新日期: 2023-09-27 18:27:22

我正在尝试将横向和纵向图像绑定到网格控件。横向图像加载正确,但我在加载纵向图像时遇到了问题。它们的底部被切掉(溢出),因此网格行无法加载具有全高的图像。我尝试将Row属性设置为Height="Auto"Height="*"

<ItemsControl ItemsSource="{Binding ItemsPrasanja}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <TextBlock 
                                    Name="txtPrasanje" 
                                    Grid.Row="0" 
                                    Text="{Binding Tekst}" 
                                    TextWrapping="Wrap"/>
                              <Image Name="imgPrasanje" 
                                    Grid.Row="1"  
                                    Source="{Binding Slika}"  
                                    Margin="0,5,0,0"
                                    />                                   
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

如何在不手动将"宽度"或"高度"设置为"栅格"或"图像"控件的情况下解决此问题?

附言:ItemsControl是另一个网格控件的一部分。它填充(Grid.Row="0"),我将其设置为Height="*"

                <Grid.RowDefinitions>
                   <RowDefinition Height="*"/>
                   <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

网格中的人像图像被截断-WP8

您应该查看Image对象的Stretch属性

值为Fill将导致图像拉伸以完全填充输出区域。当输出区域和图像具有不同的纵横比时,图像由于这种拉伸而失真。若要使图像保持图像的纵横比,请将此特性设置为"均匀"(默认值)或"均匀填充"。