【问题标题】:Phantom entries in ListViewListView 中的虚拟条目
【发布时间】:2019-08-02 15:38:33
【问题描述】:

所以我将 xamarin.forms 用于 android 和 IOS 应用程序,我的主要视图是日历,每天都有 ServerModel 的 TodayEnty 列表,我从服务器获取的数据。在 ListView 内部,我有 StackLayout 和 Bindable.Layout,它在每一天都显示整个列表,问题是当滚动副本出现在 ListView 中时。 这是问题的屏幕记录:https://drive.google.com/file/d/1PN8_nyvg-uDipVc516PXb23ztThHOAiN/view?usp=sharing

日历中填充了模拟数据,在第 16 秒的视频中看到的是全天全天的所有内容。因此,正如您所看到的,随着视频的继续,我在 ListView 中有越来越多的条目,但我的 ViewModel 列表中实际上并不存在

我真的不知道什么会导致这个问题,因为我对 xamarin.forms 很陌生。

<ListView ItemsSource="{Binding SelectedMonth.MonthDays}" x:Name="MyDaysListView">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20"/>
                                <RowDefinition Height="70"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="4*"/>
                            </Grid.ColumnDefinitions>
                            <Label Text="{Binding DayNum}" Grid.Column="0" Grid.Row="0"/>
                            <Label Text="{Binding DayName}" Grid.Column="0" Grid.Row="1"/>
                            <StackLayout BindableLayout.ItemsSource="{Binding TodayEntry}" Orientation="Vertical" Grid.Column="1" Grid.RowSpan="2">
                                <BindableLayout.ItemTemplate>
                                    <DataTemplate>
                                        <Label Text="{Binding WorkOrder}"/>
                                    </DataTemplate>
                                </BindableLayout.ItemTemplate>
                            </StackLayout>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate> 
        </ListView>

【问题讨论】:

  • 你的 XF 版本是多少?

标签: c# xaml mvvm xamarin.forms


【解决方案1】:

视图回收和BindableLayout可能存在问题...

我会尝试做什么:

  1. 看看 set CachingStrategy="RetainElement" 是否能解决问题,但它会消耗更多内存(但不会那么多,因为您最多有 30 个元素)
  2. 如果没有,我将使用ViewCellOnBindingContextChanged 事件以编程方式构建今天的条目
  3. 您也可以使用CollectionView 代替ListView,看看效果是否更好
  4. 或者如果你想要一个生产就绪的组件,你可以使用HorizontalListViewhttps://github.com/roubachof/Sharpnado.Presentation.Forms#grid-LayoutLayout=Grid and ColumnCount=1

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-01
  • 2011-05-17
  • 2018-11-24
  • 2011-01-08
相关资源
最近更新 更多