图像加载后 Xamarin 网格高度发生变化

Xamarin Grid Height changes after Images Loaded

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

我的照片也是方形的。

连接服务器前后 [1]: https://i.stack.imgur.com/lZj6F.png [2]: https://i.stack.imgur.com/ZaKQd.png

代码:

                        <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>

你试过给 Aspect="Fill" 吗?

如果您想要图像的高度 = 宽度(即方形),请为其指定硬编码的宽度或高度。

如果这在您的情况下不可行,请尝试使用 RelativeSource,其中 WidthHeight ="*" 和高度将相对于宽度像这样 WidthRequest="{Binding Source={x:Reference Self}, Path=WidthRequest}}"