Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载图像后,Xamarin栅格高度会发生变化_Xamarin_Grid - Fatal编程技术网

加载图像后,Xamarin栅格高度会发生变化

加载图像后,Xamarin栅格高度会发生变化,xamarin,grid,Xamarin,Grid,正如我在附件中所示,在连接到服务器并加载图像之前,我的网格行是方形的,但当加载图像时,它的高度会改变,变成矩形。我怎样才能避免呢?我想保留正方形的空间 我的照片也是方形的 连接到服务器之前和之后 [1]: [2] : 代码: 您是否尝试过给予Aspect=“Fill” 如果您希望图像的高度=宽度(即正方形),则为其指定硬编码的宽度或高度 如果在您的情况下不可能做到这一点,那么请尝试使用RelativeSource其中WidthHeight=“*”,高度将与宽度相关,就像这样WidthRequ

正如我在附件中所示,在连接到服务器并加载图像之前,我的网格行是方形的,但当加载图像时,它的高度会改变,变成矩形。我怎样才能避免呢?我想保留正方形的空间

我的照片也是方形的

连接到服务器之前和之后 [1]: [2] :

代码:


您是否尝试过给予
Aspect=“Fill”

如果您希望图像的高度=宽度(即正方形),则为其指定硬编码的宽度或高度


如果在您的情况下不可能做到这一点,那么请尝试使用
RelativeSource
其中
WidthHeight=“*”
,高度将与宽度相关,就像这样
WidthRequest=“{Binding Source={x:Reference Self},Path=WidthRequest}”

感谢Heightrequest完成了这项工作。Aspect=Fill并不能解决这个问题,它只是将我的图像拉伸到一个小的矩形空间上。
                        <Image x:Name="imgStation1" Grid.Row="0" Grid.Column="0" BackgroundColor="White" Source="saturday.jpg"  Aspect="AspectFill" />
                        <StackLayout Grid.Row="0" Grid.Column="0" VerticalOptions="StartAndExpand" Spacing="10" Margin="10">
                            <Label x:Name="lblLiveStation1"  Text="" FontSize="Small" TextColor="AntiqueWhite">
                                <Label.FontFamily>
                                    <OnPlatform
                         x:TypeArguments="x:String"
                         Android="gothic.ttf#gothic"
                         iOS="Optima-Regular" />
                                </Label.FontFamily>
                            </Label>
                            <Label x:Name="lblDescriptionStation1"  Text="Loading..." FontSize="Medium" FontAttributes="Bold" TextColor="FloralWhite">
                                <Label.FontFamily>
                                    <OnPlatform
                         x:TypeArguments="x:String"
                         Android="gothic.ttf#gothic"
                         iOS="Optima-Regular" />
                                </Label.FontFamily>
                            </Label>
                            <Label x:Name="lblTimeStation1"  Text="" FontSize="Small" FontAttributes="Bold" TextColor="GhostWhite">
                                <Label.FontFamily>
                                    <OnPlatform
                         x:TypeArguments="x:String"
                         Android="gothic.ttf#gothic"
                         iOS="Optima-Regular" />
                                </Label.FontFamily>
                            </Label>
                            <ImageButton x:Name="imgPlayPause0" Grid.Row="0" VerticalOptions="End" HorizontalOptions="Start" Source="playlogo.png" BackgroundColor="Transparent" Clicked="imgPlayPause0_Clicked"></ImageButton>
                        </StackLayout>
 </StackLayout>