我有一个奇怪的问题。这种情况只发生在Xamarin表格--UWP中。我在Listview中使用Listview。当我点击每个列表时,将显示子列表。我也为子列表设置了一个固定的高度,以便它可以滚动。现在检查甚至它有更多的项目黑色填充在底部。我该如何解决这个问题。
XAML列表:
<ListView x:Name="MyProducts"
IsRefreshing="{Binding IsBusy, Mode=TwoWay}"
RefreshCommand="{Binding GetAllProducts,Mode=TwoWay}"
IsPullToRefreshEnabled="true"
HasUnevenRows="True"
BackgroundColor="White"
ItemSelected="CategorySelected"
SeparatorVisibility="None"
ItemsSource="{Binding MyProductsList}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#e6e6e6" Margin="0,2,0,2">
<StackLayout Margin="1" BackgroundColor="White">
<Grid Padding="0,10,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="Product Category" YAlign="Center" Margin="10,0,0,0" Style="{DynamicResource LabelLightStyle}"/>
<Label Grid.Row="1" Grid.Column="0" Text="{Binding Model.ProductCategoryName}" Style="{DynamicResource LabelRedStyle}" YAlign="Center" Margin="10,0,0,0"/>
<Image Grid.Row="0" Grid.Column="1" IsVisible="{Binding IconDown}" Source="ArrowDown.png" HeightRequest="15" Grid.RowSpan="2" Margin="0,0,5,0" HorizontalOptions="End" VerticalOptions="Center"/>
<Image Grid.Row="0" Grid.Column="1" IsVisible="{Binding IconUp}" Source="ArrowUp.png" HeightRequest="15" Grid.RowSpan="2" Margin="0,0,5,0" HorizontalOptions="End" VerticalOptions="Center"/>
<ListView Grid.Row="2" Grid.ColumnSpan="2"
IsVisible="{Binding ListVisibility}"
SeparatorVisibility="Default"
SeparatorColor="#e6e6e6"
ItemSelected="ProductSelected"
HeightRequest="220"
BackgroundColor="#f2f2f2"
HorizontalOptions="FillAndExpand"
ItemsSource="{Binding Model.Products}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#e6e6e6">
<StackLayout Margin="0,0,0,1" BackgroundColor="#f2f2f2">
<Grid Padding="0,10,0,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding MachineModel, StringFormat='Machine Model Number : {0}'}" YAlign="Center" Margin="10,0,0,0" Style="{DynamicResource LabelStyle}"/>
<Label Grid.Row="1" Grid.Column="0" Text="{Binding CreatedDate, StringFormat='Date {0}'}" Style="{DynamicResource LabelTinyStyle}" YAlign="Center" Margin="10,0,0,0"/>
<Image Grid.Row="0" Grid.Column="1" Source="ArrowRight.png" HeightRequest="15" Grid.RowSpan="2" Margin="0,0,10,0" HorizontalOptions="End" VerticalOptions="Center"/>
</Grid>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 0 :(得分:0)
通过编写自定义ViewCell并使用本机datatemplate修复了此问题。现在快速滚动没有黑色单元格。我发布了我的答案,以便有人发现它有用。
例如:如果您要显示的名称列表如下:
首先添加自定义视单元素如下
public class CustomViewCell : ViewCell
{
public static readonly BindableProperty NameProperty =
BindableProperty.Create("Name", typeof(string), typeof(CustomViewCell), "");
public string Name
{
get { return (string)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
}
现在在XAML中添加ListView,如下所示:
<ListView
ItemsSource="{Binding Products}">
<ListView.ItemTemplate>
<DataTemplate>
<custom:CustomViewCell Name="{Binding Name}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
然后你必须在UWP项目的App.xaml中编写DateTemplate样式,如下所示:
<ResourceDictionary>
<DataTemplate x:Key="CustomTemplate">
<Grid Padding="10">
<TextBlock Foreground="#333333" FontSize="14" VerticalAlignment="Center" Text="{Binding Name"/>
</Grid>
</DataTemplate>
</ResourceDictionary>
最后编写一个CustomRenderer来将原始视单元替换为我们的ListView。
public class CustomViewCellRenderer : ViewCellRenderer
{
public override Windows.UI.Xaml.DataTemplate GetTemplate(Cell cell)
{
return App.Current.Resources["CustomTemplate"] as Windows.UI.Xaml.DataTemplate;
}
}
现在列表工作完美,没有任何黑色单元格渲染问题。