2017-06-05 25 views

回答

2

通过编写自定义ViewCell和使用本地数据模板来解决此问题。现在没有快速滚动的黑色单元格。我张贴我的答案,以便有人可能会觉得它有用。

对于例如:如果你有名称的列表将显示如下:

首先添加自定义viewcell如下

 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); } 
     } 

     } 

现在添加的ListView的XAML如下:

  <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; 
    } 
    } 

现在列表完美无缺地显示黑色单元格的问题。

0

这不是您的代码问题。滚动速度过快时,系统没有时间按滚动的速度渲染单元格,因此出现黑色单元格。

+0

luccas-clezar是的,这是正确的。这个问题只发生在UWP上。有没有什么可以解决这个问题。 – Renjith

+0

不幸的是,我不这么认为。我尝试了几种提高性能的方法(例如试图删除绑定并对PropertyChanged或BindingContextChanged中的单元格进行更改),但我没有注意到任何性能增加。 –

+0

您好通过自定义ViewCell解决了这个问题。我已经写了customrenderer来解决这个问题。现在没有快速滚动的黑色单元格。我在下面添加了我的答案。 – Renjith