Xamarin.forms - Gridview 行高错误

Xamarin.forms - Gridview row height error

我的 ContentPage 在 ListView 中有一个 Grid,其中包含一个带有标签和图像的列 (x:Name="stlNomeMiniatura"),如下所示:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="InventarioBensCelular.MainPage"
             BackgroundColor="White">

    <ContentPage.Content>
        <StackLayout>
            <StackLayout Orientation="Vertical" VerticalOptions="Start" HeightRequest="130" Background="#003399">
                <StackLayout Orientation="Horizontal" HorizontalOptions="Start" VerticalOptions="Start" HeightRequest="40" Margin="7,10">
                    <StackLayout Orientation="Horizontal">
                        <Image Source="Icone.png" Aspect="Fill" HeightRequest="40" WidthRequest="48" VerticalOptions="Center" 
                               HorizontalOptions="Start"/>
                    </StackLayout>
                    <StackLayout Orientation="Horizontal" WidthRequest="300" HeightRequest="40">
                        <StackLayout Orientation="Vertical">
                            <Label x:Name="lblTitulo" Text="Inventário de Bens" FontSize="17" FontAttributes="Bold" 
                       VerticalOptions="Start" TextColor="White" Padding="0,-2,0,0"/>
                            <Label x:Name="lblSubtitulo" Text="Transmissão de Foto" FontSize="17" FontAttributes="Bold" 
                       VerticalOptions="Start" TextColor="White" Padding="0,-7,0,0"/>
                        </StackLayout>
                    </StackLayout>
                    <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand" VerticalOptions="Center" HeightRequest="40">
                        <ImageButton Source="ParametrosVerde.png" HorizontalOptions="Center" VerticalOptions="Center"
                             HeightRequest="32" WidthRequest="32" Clicked="Parametro_Clicou"/>
                    </StackLayout>
                </StackLayout>
                <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" VerticalOptions="Start">
                    <StackLayout WidthRequest="160" Margin="7,0">
                        <Frame x:Name="TiraFoto" CornerRadius="10" BorderColor="DarkGreen" HorizontalOptions="StartAndExpand"
                    Padding="0" HeightRequest="32" VerticalOptions="Start" BackgroundColor="#E0FFE0" WidthRequest="160">
                            <Frame.GestureRecognizers>
                                <TapGestureRecognizer Tapped="TiraFoto_Clicou" />
                            </Frame.GestureRecognizers>
                            <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand" Padding="10,0,0,0">
                                <Image Source="Camera.png" Aspect="Fill" HeightRequest="26" WidthRequest="24" VerticalOptions="Center" HorizontalOptions="Start"/>
                                <Label Text="Tirar Uma Foto" FontSize="16" FontAttributes="Bold" VerticalTextAlignment="Center" HorizontalOptions="Start"
                            TextColor="DarkGreen"/>
                            </StackLayout>
                        </Frame>
                    </StackLayout>
                    <StackLayout WidthRequest="160">
                        <Frame x:Name="Sair" CornerRadius="10" BorderColor="Red"
                    Padding="0" HeightRequest="32" VerticalOptions="Start" BackgroundColor="#FFE8E8" WidthRequest="160">
                            <Frame.GestureRecognizers>
                                <TapGestureRecognizer Tapped="Sair_Clicou" />
                            </Frame.GestureRecognizers>
                            <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand" Padding="10,0,0,0">
                                <Image Source="Sair.png" Aspect="Fill" HeightRequest="24" WidthRequest="24" VerticalOptions="Center" HorizontalOptions="Start"
                                       IsAnimationPlaying="True"/>
                                <Label Text="Sair Programa" FontSize="16" FontAttributes="Bold" VerticalTextAlignment="Center" HorizontalOptions="Start"
                            TextColor="Red"/>
                            </StackLayout>
                        </Frame>
                    </StackLayout>
                    <StackLayout>
                    </StackLayout>
                    <StackLayout Margin="0,-2">
                        <Frame x:Name="WiFi" CornerRadius="10" BorderColor="#003399"
                    Padding="0" HeightRequest="35" VerticalOptions="Center" BackgroundColor="White" WidthRequest="35">
                            <Frame.GestureRecognizers>
                                <TapGestureRecognizer Tapped="WiFi_Clicou" />
                            </Frame.GestureRecognizers>
                            <Image x:Name="imgWiFiStatus" Source="WifiVermelho.gif" Aspect="Fill" HeightRequest="24" WidthRequest="24" 
                           VerticalOptions="Center" HorizontalOptions="Center"/>
                        </Frame>
                    </StackLayout>
                </StackLayout>
            </StackLayout>
            <Frame BackgroundColor="Transparent" HeightRequest="25" Padding="0" VerticalOptions="Center" Margin="10,0">
                <Label Text="Arquivos a Transmitir:" FontSize="15" FontAttributes="Bold"
                       VerticalOptions="Start" TextColor="#003399"/>
            </Frame>
            <StackLayout Margin="10,0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                <ListView x:Name="ltvArquivoLista" SeparatorVisibility="None" SelectionMode="None" HasUnevenRows="False" IsPullToRefreshEnabled = "True">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <Grid BackgroundColor="Transparent">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="169"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="347"></ColumnDefinition>
                                        <ColumnDefinition Width="40"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>


                                    <StackLayout  x:Name="stlNomeMiniatura" Grid.Row="0" Grid.Column="0" Orientation="Vertical"
                                                 HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand">
                                        <Label Text="{Binding Nome, Mode=OneWay}" FontSize="15" 
                                               VerticalOptions="Start" TextColor="#003399"/>
                                        <Image Source="{Binding Miniatura, Mode=OneWay}" Aspect="AspectFit"
                                               VerticalOptions="Start" 
                                               HorizontalOptions="Start"/>
                                    </StackLayout>


                                    <StackLayout Grid.Row="0" Grid.Column="1" Orientation="Vertical"
                                                 HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand">
                                        <Image x:Name="cmdExcluirFoto" Source="{Binding BotaoExcluirImagem, Mode=OneWay}" Aspect="AspectFill"
                                               HeightRequest="32" WidthRequest="32" VerticalOptions="Start" HorizontalOptions="Start">
                                            <Image.GestureRecognizers>
                                                <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="Foto_Excluir_Clicou"/>
                                            </Image.GestureRecognizers>
                                        </Image>
                                    </StackLayout>
                                </Grid>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

在 .CS 文件中,我有以下代码显示了如何使用 ObservableCollection“Arquivo”设置 ListView ItemsSource:

        public ObservableCollection<Arquivo> Arquivos = new ObservableCollection<Arquivo>();

    private List<string> ArquivosATransmitir = null;
    private DateTime TestaConexaoIntervaloDtInicio = Convert.ToDateTime("2000/01/01 00:00:00");
    private DateTime TestaConexaoIntervaloDtFim = Convert.ToDateTime("2000/01/01 00:00:00");

    public MainPage()
    {
        InitializeComponent();

        DeviceInfo = new DeviceInfo.CDeviceInfo();

        Rotinas.File_Found("Inventario.ini", DeviceInfo.Info.Application.DataFolder, false, @"/");
        if (Rotinas.INIFileName == null)
        {
            Rotinas.INIFileName = DeviceInfo.Info.Application.DataFolder + @"/Inventario.ini";
            Rotinas.INI_Write("[SISTEMA]", "Titulo", "Inventário de Bens");
            Rotinas.INI_Write("[SISTEMA]", "Subtitulo", "Transmissão de Fotos");
            Rotinas.INI_Write("[SERVIDOR]", "IP", "192.168.0.22");
            Rotinas.INI_Write("[SERVIDOR]", "Porta", "1234");
        }

        TituloSistema = Rotinas.INI_Read("[SISTEMA]", "Titulo");
        Subtitulo = Rotinas.INI_Read("[SISTEMA]", "Subtitulo");
        ServidorIP = Rotinas.INI_Read("[SERVIDOR]", "IP");
        if (ServidorIP != "")
        {
            string auxPorta = Rotinas.INI_Read("[SERVIDOR]", "Porta");
            if (auxPorta != null)
            {
                ServidorPorta = auxPorta;
            }
            else
            {
                ServidorPorta = "1234";
            }
        } else
        {
            ServidorIP = null;
            ServidorPorta = null;
        }

        this.lblTitulo.Text = TituloSistema;
        this.lblSubtitulo.Text = Subtitulo;

        ConexaoServidor = new Connection();

        ConexaoServidor.FileTypeName = "Fotos";

        DiretorioArquivosATransmitir = DeviceInfo.Info.Application.DataFolder + @"/ArquivosATransmitir";
        if (!Directory.Exists(DiretorioArquivosATransmitir))
        {
            Directory.CreateDirectory(DiretorioArquivosATransmitir);
        }
        ArquivosATransmitir = Directory.GetFiles(DiretorioArquivosATransmitir, "*.*", SearchOption.AllDirectories)
                              .Where(file => new string[] { ".jpg" }.Contains(Path.GetExtension(file))).ToList();
        if (ArquivosATransmitir.Count > 0)
        {
            for (int Ctr = 0; Ctr <= ArquivosATransmitir.Count - 1; Ctr++)
            {
                GridArquivo_Incluir(ArquivosATransmitir[Ctr]);
            }
        }

        ltvArquivoLista.ItemsSource = Arquivos;

        Testa_Conexao_Servidor();
    }

我希望它显示如下:

但是,GridView 显示的行高固定,图像被截断,如下所示:

我做错了什么?

提前致谢,抱歉我的英语不好。

马塞洛·​​卡马拉特

您可以尝试修改您的代码如下:

1.change 属性 HasUnevenRows 的值从 FalseTrue 用于您的列表视图 (ltvArquivoLista)

 HasUnevenRows="True"

2.change Height of RowDefinition169*Auto;

                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="347"></ColumnDefinition>
                            <ColumnDefinition Width="40"></ColumnDefinition>
                        </Grid.ColumnDefinitions>