修改 ListView 项时自动调整 ListView 高度 [英] Auto size ListView height when ListView item gets modified

查看:23
本文介绍了修改 ListView 项时自动调整 ListView 高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调整列表视图行的大小以匹配其中的文本时遇到了一些问题.此外,我阅读了大量文档,似乎所有内容都指向使用 HasUnevenRows,我正在使用它,但并不是我所需要的.

I have been having some issues resizing my list view row to match the text inside of it. Also I have read a lot of documentation and everything seems to point toward using HasUnevenRows, which I am using but isn't quite what I need.

我有一个 ListView,我允许用户使用 Rg.Popups 和上下文操作修改该行的内容.基本上,用户滑动并单击编辑",然后他们会被推送到一个弹出窗口,在那里他们可以编辑列表视图项.

I have a ListView which I allow the user to modify contents of this row using Rg.Popups and context actions. Essentially the user swipes and clicks Edit and they get pushed to a popup where they can edit the list view item.

当笔记更新时,它也会在我的 ListView 上更新,但是如果笔记超过 1 行,该行将不会调整大小.我必须离开该页面并返回该页面以调整该行的大小以适合整个笔记.

When the note gets updated it also gets updated on my ListView however if the note is more than 1 line the row will not resize. I have to leave the page and come back to it for the row to resize to fit the entire note.

下面是我的代码.

  <ListView  x:Name="MyItemList"
                       HorizontalOptions="Center"
                       ItemSelected="OpenRecipeDetails"
                       IsGroupingEnabled="True"
                       HasUnevenRows="true">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell x:Name="myViewcell">
                            <ViewCell.ContextActions>
                                <MenuItem Clicked="MenuItem_Clicked" Text="Edit Note" CommandParameter="{Binding .}"/>
                            </ViewCell.ContextActions>
                            <StackLayout>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Label Text="{Binding Title}"
                                            Grid.Row="0"
                                            Grid.Column="0"
                                            FontSize="{Binding BindingContext.H1Font, Source={x:Reference Name=ThisPage}}"
                                            Padding="5"
                                            
                                            LineBreakMode="WordWrap">
                                    </Label>
                                    <Label Text="{Binding sNote}"
                                           Grid.Row="1"
                                           Grid.Column="0"  
                                           FontSize="{Binding BindingContext.H2Font, Source={x:Reference Name=ThisPage}}"
                                          >
                                    </Label>
                                </Grid>
                               <!-- -->
                            </StackLayout>
                        </ViewCell>

                    </DataTemplate>
                </ListView.ItemTemplate>
             </ListView>

代码隐藏

//for editing the note
 async void MenuItem_Clicked(System.Object sender, System.EventArgs e)
        {
            var menuItem = sender as MenuItem;
            updatedItem = menuItem.CommandParameter as MyItemBooklet;
            await PopupNavigation.Instance.PushAsync(new EditNotesPopupPage(updatedItem));
        }

EditNotesPopupPage

EditNotesPopupPage

 public EditNotesPopupPage( MyItemBooklet item)
        {
            InitializeComponent();
            _item = item;
        }
...
  async void Cancel_Clicked(System.Object sender, System.EventArgs e)
        {
            await PopupNavigation.Instance.PopAllAsync();
        }

       async void Ok_Clicked(System.Object sender, System.EventArgs e)
        {
           ...
           ...

            await db.UpdateNote(text, _item.iRecipeLinkID);
            await PopupNavigation.Instance.PopAllAsync();
        }

推荐答案

您可以尝试强制更新 ViewCell 的大小,下面是指导您的良好示例链接:

You can try force update size of ViewCell below is the link with good sample that will guide you:

https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/userinterface-listview-dynamicunevenlistcells/

这篇关于修改 ListView 项时自动调整 ListView 高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆