【问题标题】:Portrait Images in Grid are cutoff - WP8网格中的人像图像被截断 - WP8
【发布时间】:2013-08-11 01:21:56
【问题描述】:

我正在尝试将横向和纵向图像绑定到网格控件。横向图像已正确加载,但在加载纵向图像时我遇到了问题。它们的底部被切断(溢出),因此网格行无法加载完整高度的图像。我尝试使用 Height="Auto"Height="*" 设置 Row 属性,但这不起作用。 这是我的 XAML:

<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 控件的一部分。它填充了我设置为 Height=" * "

的 (Grid.Row="0")
                <Grid.RowDefinitions>
                   <RowDefinition Height="*"/>
                   <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

【问题讨论】:

  • 试用要在 XAML 中设置的图像拉伸属性。
  • 我已经尝试过使用 Stretch="None"、Stretch="UniformToFill" 和 Stretch="Fill" 但没有效果。 Stretch="Uniform" 默认设置。

标签: c# image windows-phone-7 windows-phone-8 windows-phone


【解决方案1】:

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

Fill 值将导致您的图像拉伸以完全填满输出区域。当输出区域和图像具有不同的纵横比时,图像会因这种拉伸而失真。要使 Image 保持图像的纵横比,请将此属性设置为 Uniform(默认)或 UniformToFill。

【讨论】:

  • 我已经尝试了所有的 Stretch 属性,但它们没有任何效果。图像仍然被裁剪。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-27
  • 1970-01-01
相关资源
最近更新 更多