简体   繁体   English

最后一行作为 ListView Xamarin 表单中的截止值

[英]Last row as cuttoff in ListView Xamarin forms

I am learning xamarin forms and so far I have been able to advance with the help of the forum and the Internet, but I am having a problem that I can not solve.我正在学习 xamarin 表单,到目前为止我已经能够在论坛和互联网的帮助下取得进步,但是我遇到了无法解决的问题。 In summary, I have a Listview that shows a data collection and I use mvvm.总之,我有一个显示数据集合的 Listview,我使用 mvvm。 The problem is that when viewing it on the mobile, the last row is cut off and the buttons at the bottom of the page are not displayed either.问题是,在手机上查看时,最后一行被截断了,页面底部的按钮也没有显示。 I have read several topics and have tried several things, but none works.我已经阅读了几个主题并尝试了几件事,但都没有奏效。 PS: I can not establish a fixed height, it has to be dynamic, depending on the size of the data. PS:我不能建立一个固定的高度,它必须是动态的,取决于数据的大小。

<StackLayout Style = "{StaticResource whiteBody}">
            <FlexLayout Direction = "Column" VerticalOptions = "FillAndExpand">
                <Grid VerticalOptions = "FillAndExpand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height = "Auto" />
                        <RowDefinition Height = "Auto" />
                        <RowDefinition Height = "Auto" />
                        <RowDefinition Height = "Auto" />
                        <RowDefinition Height = "*" />
                    </ Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width = "Auto" />
                        <ColumnDefinition Width = "*" />
                    </Grid.ColumnDefinitions>

                    <StackLayout Grid.Column = "0" Grid.Row = "0" Grid.ColumnSpan = "2" Style = "{StaticResource redBar}">
                        <Label Style = "{StaticResource whiteText}" Text = "OFFER FINDER" HorizontalOptions = "StartAndExpand"
                                AutomationProperties.IsInAccessibleTree = "True"
                                AutomationProperties.HelpText = "My offers"
                                AutomationProperties.Name = "My offers" />
                        <Label Style = "{StaticResource whiteText}" Text = "MENU" x: Name = "menuLink" HorizontalOptions = "EndAndExpand"
                                AutomationProperties.IsInAccessibleTree = "True"
                                AutomationProperties.HelpText = "Back to menu"
                                AutomationProperties.Name = "Menu">
                            <! - <Label.GestureRecognizers>
                                    <TapGestureRecognizer Command = "{Binding NavigateCommand}" CommandParameter = "{x: Local Type: MenuView}"
                                        NumberOfTapsRequired = "1" />
                                </Label.GestureRecognizers> ->
                        </ Label>
                    </ StackLayout>

                    <StackLayout Grid.Column = "0" Grid.Row = "1" Grid.ColumnSpan = "2" Style = "{StaticResource backSave}">
                        <Label Style = "{StaticResource redText}" Text = "Return" HorizontalOptions = "StartAndExpand"
                                AutomationProperties.IsInAccessibleTree = "True"
                                AutomationProperties.HelpText = "Back to the offers search"
                                AutomationProperties.Name = "Back to search engine" />
                        <Label Style = "{StaticResource redText}" Text = "Save search" x: Name = "saveSearch" HorizontalOptions = "End"
                                AutomationProperties.IsInAccessibleTree = "True"
                                AutomationProperties.HelpText = "Save search"
                                AutomationProperties.Name = "Save search">
                            <! - <Label.GestureRecognizers>
                                    <TapGestureRecognizer Command = "{Binding NavigateCommand}" CommandParameter = "{x: Local Type: MenuView}"
                                        NumberOfTapsRequired = "1" />
                                </Label.GestureRecognizers> ->
                        </ Label>
                    </ StackLayout>
                    <FlexLayout Direction = "Column" Grid.Column = "0" Grid.Row = "2" Grid.ColumnSpan = "2" HeightRequest = "1">
                        <BoxView Style = "{StaticResource lineHorz}" AutomationProperties.IsInAccessibleTree = "False" />
                    </ FlexLayout>
                    <! - Square content ->
                        <ListView Grid.Column = "0" Grid.Row = "3" Grid.ColumnSpan = "2" HasUnevenRows = "True" ItemsSource = "{Binding DealsList}"
                                   x: Name = "OffersListView" SeparatorVisibility = "Default" HeightRequest = "1000">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell>
                                    <StackLayout Style = "{StaticResource resultStack}" VerticalOptions = "FillAndExpand">
                                            <StackLayout x: Name = "stackFavorites" Style = "{StaticResource favsStack}">
                                                <BoxView BackgroundColor = "Gray" HorizontalOptions = "Start" VerticalOptions = "Center"
                                                     HeightRequest = "45" WidthRequest = "45" Margin = "25,0,0,0"
                                                    AutomationProperties.IsInAccessibleTree = "False" />
                                                <Label Text = "{Binding stateFav}" VerticalOptions = "Center" Margin = "5"> </ Label>
                                                <StackLayout.GestureRecognizers>
                                                    <TapGestureRecognizer Command = "{Binding changeFav}" NumberOfTapsRequired = "1" />
                                                </StackLayout.GestureRecognizers>

Do you want to achieve the result like following GIF??(I do not know what is your styles of every control, so i delete it)你想达到像下面GIF那样的效果吗??(我不知道你每个控件的风格是什么,所以我删除了它)

在此处输入图片说明

If you want to achieve that, Pease wrap a ScrollView outside the stacklayout like following code.( I delete the height of listview , it can be adjusted height by the content)如果你想实现这一点,Pease 像下面的代码一样在stacklayout外面包裹一个ScrollView 。(我删除了listview的高度,它可以通过内容调整高度)

    <ScrollView>
    <StackLayout>
        <FlexLayout  Direction = "Column" VerticalOptions = "FillAndExpand">
        <Grid VerticalOptions = "FillAndExpand">
            <!--5 行 2列 -->

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

            <StackLayout Grid.Column = "0" Grid.Row = "0" Grid.ColumnSpan = "2">
                <Label  Text = "OFFER FINDER" HorizontalOptions = "StartAndExpand"
                            AutomationProperties.IsInAccessibleTree = "True"
                            AutomationProperties.HelpText = "My offers"
                            AutomationProperties.Name = "My offers" />
                <Label  Text = "MENU" x:Name = "menuLink" HorizontalOptions = "EndAndExpand"
                            AutomationProperties.IsInAccessibleTree = "True"
                            AutomationProperties.HelpText = "Back to menu"
                            AutomationProperties.Name = "Menu">

                </Label>
            </StackLayout>

            <StackLayout Grid.Column = "0" Grid.Row = "1" Grid.ColumnSpan = "2" >
                <Label  Text = "Return" HorizontalOptions = "StartAndExpand"
                            AutomationProperties.IsInAccessibleTree = "True"
                            AutomationProperties.HelpText = "Back to the offers search"
                            AutomationProperties.Name = "Back to search engine" />
                <Label  Text = "Save search" x:Name = "saveSearch" HorizontalOptions = "End"
                            AutomationProperties.IsInAccessibleTree = "True"
                            AutomationProperties.HelpText = "Save search"
                            AutomationProperties.Name = "Save search">

                </Label>
            </StackLayout>

            <FlexLayout Direction = "Column" Grid.Column = "0" Grid.Row = "2" Grid.ColumnSpan = "2" HeightRequest = "1">
                <BoxView  AutomationProperties.IsInAccessibleTree = "False" />
            </FlexLayout>
            <!-- Square content -->
            <ListView Grid.Column = "0" Grid.Row = "3" Grid.ColumnSpan = "2" HasUnevenRows = "True" 
                               x:Name = "OffersListView" SeparatorVisibility = "Default" >
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout  VerticalOptions = "FillAndExpand">
                                <StackLayout x:Name = "stackFavorites" >
                                    <BoxView BackgroundColor = "Gray" HorizontalOptions = "Start" VerticalOptions = "Center"
                                                 HeightRequest = "45" WidthRequest = "45" Margin = "25,0,0,0"
                                                AutomationProperties.IsInAccessibleTree = "False" />
                                    <Label Text = "{Binding stateFav}" VerticalOptions = "Center" Margin = "5"></Label>
                                    <!--    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer Command = "{Binding changeFav}" NumberOfTapsRequired = "1" />
                                    </StackLayout.GestureRecognizers> -->
                                </StackLayout>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <StackLayout Grid.Column = "0" Grid.Row = "4" Grid.ColumnSpan = "2" >


                <Grid VerticalOptions = "FillAndExpand" >
                    <!--5 行 2列 -->

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Button  Text="Button1" Grid.Column = "0" Grid.Row = "0" />
                    <Button  Text="Button2"  Grid.Column = "1" Grid.Row = "0" />
                </Grid>
            </StackLayout>
        </Grid>
    </FlexLayout>
    </StackLayout>
</ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM