В настоящее время у меня есть listView с элементами строк в кроссплатформенном приложении Xamarin Forms.Представление списка связано с ObservableCollection, имеющим переменную IsAnimated, которая указывает, должен ли ящик открываться или закрываться (т. Е. Представление переводится влево или вправо).
Для этогочтобы быть открытым или закрытым в правильных местах при прокрутке, я создал Custom ViewCell, который проверяет, когда ViewCell появляется.Когда он появляется, он проверяет переменную IsAnimated, а затем соответственно открывает или закрывает ящик.
Теперь, когда я провожу отрицательное тестирование и быстро прокручиваю вверх и вниз, он скрывает мое представление и оставляет пустые пробелы в моем списке.
Как я могу запретить этим пустым пространствам захватывать элементы строк?
Мой адаптер Viewcell:
class DirectoryListViewCell : ViewCell
{
protected override void OnAppearing()
{
var view = this.View.Parent;
var binding = (this.BindingContext as DirectoryModel);
var meh = (view as ViewCell).View;
var abs = (meh as AbsoluteLayout).Children.FirstOrDefault();
var width = Application.Current.MainPage.Width;
var trans = (((-1 * width) / 10) * 4);
switch (binding.IsAnimated)
{
case false:
abs.TranslateTo(0, 0, 0, Easing.Linear);
break;
case true:
abs.TranslateTo(200, 0, 0, Easing.Linear);
break;
}
base.OnAppearing();
}
}
И моя таблица данных представления списка Xaml выглядит так
<custom:DirectoryListViewCell>
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeightRequest="80">
<AbsoluteLayout AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="White">
<Image AbsoluteLayout.LayoutBounds="0, 0, 0.2, 1" AbsoluteLayout.LayoutFlags="All"
Source="contact_image.png" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="10"/>
<StackLayout AbsoluteLayout.LayoutBounds="0.4, 0, 0.5, 0.25" AbsoluteLayout.LayoutFlags="All" Orientation="Horizontal">
<Label Text="{Binding DisplayName, Converter={StaticResource NullToTitleConverter}}" LineBreakMode="CharacterWrap" HorizontalTextAlignment="Start" FontSize="Small" VerticalTextAlignment="Center"></Label>
<Label Text="{Binding DisplayRecommendedTitle}" LineBreakMode="CharacterWrap" HorizontalTextAlignment="Start" FontSize="Micro" TextColor="Gray" VerticalTextAlignment="Center"></Label>
</StackLayout>
<Label Text="{Binding Number}"
AbsoluteLayout.LayoutBounds="0.4, 0.5, 0.5, 0.4" AbsoluteLayout.LayoutFlags="All" VerticalTextAlignment="Center"></Label>
<Label Text="{Binding CallCount, Converter={StaticResource CallCountConverter}}" FontSize="Micro"
AbsoluteLayout.LayoutBounds="0.4, 0.941, 0.5, 0.15" AbsoluteLayout.LayoutFlags="All" VerticalTextAlignment="Center"></Label>
<Image AbsoluteLayout.LayoutBounds="0.824, 0, 0.15, 1" AbsoluteLayout.LayoutFlags="All"
Source="edit_contact.png" VerticalOptions="Center" HorizontalOptions="CenterAndExpand" Margin="10"></Image>
<Button x:Name="btnExpand" Image="expand_options.png" AbsoluteLayout.LayoutBounds="1, 0, 0.15, 1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="Transparent">
<Button.Triggers>
<EventTrigger Event="Clicked">
<triggers:ClickTranslation/>
</EventTrigger>
</Button.Triggers>
</Button>
</AbsoluteLayout>
<StackLayout AbsoluteLayout.LayoutBounds="0.75, 0, 0.2, 1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="#00bcae" Padding="25" IsVisible="{Binding IsAnimated}">
<Image AbsoluteLayout.LayoutBounds="0.8,0.5,1,1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="#00bcae"
Source="business_white.png" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"></Image>
</StackLayout>
<StackLayout AbsoluteLayout.LayoutBounds="1, 0, 0.2, 1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="Gray" Padding="25" IsVisible="{Binding IsAnimated}">
<Image AbsoluteLayout.LayoutBounds="1,0.5,1,1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="Gray"
Source="personal_white.png" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"></Image>
</StackLayout>
</AbsoluteLayout>
</custom:DirectoryListViewCell>