2017-06-05 50 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

相關問題