Listview中的高度与stacklayout中的imagecell

时间:2017-03-21 14:12:44

标签: xaml listview xamarin xamarin.forms frame

我遇到了问题。我在Listview内部有一个imagecell,在一个Frame内部,我将所有内容放在stacklayout中。 我的问题是带有图像单元的框架的高度太贵了。现在,我只有2个项目,但高度就像页面的大小。

XAML代码:

 <AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
    <StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
        <ScrollView>
            <StackLayout Padding="10,20,10,10">
              <Frame x:Name="frameOpcoes"  OutlineColor="Gray" HasShadow="True" VerticalOptions="Fill" HorizontalOptions="FillAndExpand" BackgroundColor="White">
                    <StackLayout Padding="0,10,0,0" Orientation="Vertical">
                        <StackLayout Orientation="Horizontal"  HorizontalOptions="FillAndExpand">

                            <StackLayout Orientation="Vertical"  HorizontalOptions="Start">
                                <Label x:Name="lblOpcoes" Text="Placa: " TextColor="Gray" FontAttributes="Bold"/>
                            </StackLayout>

                            <StackLayout Orientation="Vertical"  HorizontalOptions="FillAndExpand">
                                <Entry x:Name="entryPlacaLetra" TextChanged="entryLetra_TextoAlterado" Keyboard="Text"  TextColor="Black" BackgroundColor="#D3D3D3" />
                            </StackLayout>

                            <StackLayout Orientation="Vertical"  HorizontalOptions="Fill">
                                <Label x:Name="lblTraco" Text="-" TextColor="Gray" FontAttributes="Bold"/>
                            </StackLayout>

                            <StackLayout Orientation="Vertical"  HorizontalOptions="FillAndExpand">
                                <Entry x:Name="entryPlacaNum" TextChanged="entryNum_textoAlterado" Keyboard="Numeric" TextColor="Black" BackgroundColor="#D3D3D3"/>
                            </StackLayout>

                        </StackLayout>

                        <StackLayout VerticalOptions="FillAndExpand">
                            <ListView x:Name="listView" HorizontalOptions="FillAndExpand" VerticalOptions="Start" HasUnevenRows="True" SeparatorVisibility="None">
                                    <ListView.ItemTemplate>
                                        <DataTemplate >
                                            <ImageCell Text="{Binding Title}" Detail="{Binding Detail}" DetailColor="Gray" TextColor="Black" ImageSource="{Binding IconSource}" />
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                        </StackLayout>

                    </StackLayout>
                </Frame>
                <StackLayout Padding="0,30,0,0" x:Name="stckCalculo" VerticalOptions="EndAndExpand">
                    <Button x:Name="btnCalcular" BorderColor="Silver" BackgroundColor="Red" TextColor="White" Text="Prosseguir" />
                </StackLayout>
            </StackLayout>
        </ScrollView>
    </StackLayout>
    <StackLayout IsVisible="{Binding IsBusy}" Padding="12"
          AbsoluteLayout.LayoutFlags="PositionProportional"
          AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">
        <Frame Padding="50" OutlineColor="Black" HasShadow="true" AbsoluteLayout.LayoutFlags="PositionProportional" Opacity="0.8" BackgroundColor="Black" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
            <ActivityIndicator  IsRunning="{Binding IsBusy}" Color ="White"/>
            <Label Text="Aguarde..." HorizontalOptions="Center" TextColor="White"/>
        </Frame>
     </StackLayout>
 </AbsoluteLayout>

1 个答案:

答案 0 :(得分:0)

您可以像这样创建自定义单元格

<ListView  x:Name="listView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                        <StackLayout Orientation="Horizontal">
                            <Image Source="{Binding image}" />
                            <Label Text="{Binding title}"
                            TextColor="#f35e20" />
                        </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>