Note that there are some explanatory texts on larger screens.

plurals
  1. POSlow wpf ItemsControl refresh on ListCollectionView
    primarykey
    data
    text
    <p>The problem I have is my listcollectionview is taking 3-4 seconds to update. I think I have the virtualization configured correctly; however, please point out if it is incorrect. I have my itemssource bound to a ICollectionView.</p> <p>If i set the loop to 3000+ in BindingViewModel UI takes a long time to launch even though it takes less than a second to build the ViewModels. </p> <p>I don't know how to attach files so I'll post all the sample code that reproduces this problem:</p> <p>BigList.Xaml: ` </p> <pre><code> &lt;Style x:Key="textBlockBaseStyle" TargetType="TextBlock"&gt; &lt;Setter Property="Foreground" Value="Blue"/&gt; &lt;/Style&gt; &lt;Style x:Key="headerButtonStyle" TargetType="Button"&gt; &lt;Setter Property="FontWeight" Value="Bold"/&gt; &lt;Setter Property="Foreground" Value="Blue"/&gt; &lt;Setter Property="Background" Value="Transparent" /&gt; &lt;Setter Property="HorizontalContentAlignment" Value="Stretch"/&gt; &lt;Setter Property="BorderBrush" Value="Transparent"/&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter Property="Background" Value="DarkBlue"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;Style x:Key="borderBaseStyle" TargetType="Border"&gt; &lt;Setter Property="BorderBrush" Value="Blue"/&gt; &lt;/Style&gt; &lt;!--these two styles let us cascadingly style on the page without having to specify styles apparently styles don't cascade into itemscontrols... in the items control we must reference via key --&gt; &lt;Style TargetType="TextBlock" BasedOn="{StaticResource textBlockBaseStyle}"/&gt; &lt;Style TargetType="Border" BasedOn="{StaticResource borderBaseStyle}"/&gt; &lt;!-- hover styles --&gt; &lt;Style x:Key="onmouseover" TargetType="{x:Type Border}" BasedOn="{StaticResource borderBaseStyle}"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter Property="Background" Value="DarkBlue"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/UserControl.Resources&gt; &lt;Grid&gt; &lt;StackPanel Width="390"&gt; &lt;!-- Header--&gt; &lt;Border BorderThickness="1,1,1,1"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="55"/&gt; &lt;ColumnDefinition Width="70"/&gt; &lt;ColumnDefinition Width="70"/&gt; &lt;ColumnDefinition Width="70"/&gt; &lt;ColumnDefinition Width="70"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Button Command="{Binding SortFirstNameCommand}" Style="{StaticResource headerButtonStyle}" Grid.Column="1" &gt; &lt;TextBlock TextAlignment="Left" Text="First"/&gt; &lt;/Button&gt; &lt;Button Style="{StaticResource headerButtonStyle}" Grid.Column="2" &gt; &lt;TextBlock TextAlignment="Left" Text="Last"/&gt; &lt;/Button&gt; &lt;Button Style="{StaticResource headerButtonStyle}" Grid.Column="3" &gt; &lt;TextBlock TextAlignment="Left" Text="Activity"/&gt; &lt;/Button&gt; &lt;Button Style="{StaticResource headerButtonStyle}" Grid.Column="4"&gt; &lt;TextBlock TextAlignment="Left" Text="Last Activity"/&gt; &lt;/Button&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;Border BorderThickness="1,0,1,1"&gt; &lt;ItemsControl VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{Binding UsersAvailForEmail}" MaxHeight="400"&gt; &lt;ItemsControl.Template&gt; &lt;ControlTemplate&gt; &lt;ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" IsDeferredScrollingEnabled="True" Padding="{TemplateBinding Padding}"&gt; &lt;ItemsPresenter/&gt; &lt;/ScrollViewer&gt; &lt;/ControlTemplate&gt; &lt;/ItemsControl.Template&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Border Style="{StaticResource onmouseover}" BorderThickness="0,0,1,1"&gt; &lt;CheckBox Margin="20,5" IsChecked="{Binding IsSelected}"&gt; &lt;CheckBox.Content&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Width="20"/&gt; &lt;TextBlock Width="70" Style="{StaticResource textBlockBaseStyle}" Grid.Column="1" Text="{Binding FirstName}"/&gt; &lt;TextBlock Width="70" Style="{StaticResource textBlockBaseStyle}" Grid.Column="2" Text="{Binding LastName}"/&gt; &lt;TextBlock Width="70" Style="{StaticResource textBlockBaseStyle}" Grid.Column="3" Text="{Binding Action}"/&gt; &lt;TextBlock Width="60" Style="{StaticResource textBlockBaseStyle}" Grid.Column="4" Text="{Binding ActionId}"/&gt; &lt;/StackPanel&gt; &lt;/CheckBox.Content&gt; &lt;/CheckBox&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;/Border&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p> `</p> <p>BindingViewModel.cs:</p> <pre><code>using System.Linq; using System.Text; using System.ComponentModel; using System.Collections.ObjectModel; using System.Windows.Data; namespace LargeItemsCollection { public class BindingViewModel : INotifyPropertyChanged { ObservableCollection&lt;EmailPersonViewModel&gt; _usersAvail = new ObservableCollection&lt;EmailPersonViewModel&gt;(); ListCollectionView _lvc = null; public BindingViewModel() { for (int i = 0; i &lt; 4000; i++) { _usersAvail.Add( new EmailPersonViewModel { FirstName = "f" +i.ToString() , LastName= "l" + i.ToString(), Action= "a" + i.ToString(), ActionId="ai" + i.ToString(), IsSelected=true }); } _lvc = new ListCollectionView(_usersAvail); } public ICollectionView UsersAvailForEmail { get { return _lvc; } } /// &lt;summary&gt; /// Raised when a property on this object has a new value. /// &lt;/summary&gt; public event PropertyChangedEventHandler PropertyChanged; /// &lt;summary&gt; /// Raises this object's PropertyChanged event. /// &lt;/summary&gt; /// &lt;param name="propertyName"&gt;The property that has a new value.&lt;/param&gt; public virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { var e = new PropertyChangedEventArgs(propertyName); handler(this, e); } } } </code></pre> <p>EmailPersonViewModel.cs:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LargeItemsCollection { public class EmailPersonViewModel { public string FirstName { get; set; } public string LastName { get; set; } public string Action { get; set; } public string ActionId { get; set; } public bool IsSelected { get; set; } public EmailPersonViewModel() { } } } </code></pre> <p>MainWindow.xaml:</p> <pre><code>&lt;Window x:Class="LargeItemsCollection.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:LargeItemsCollection" Title="MainWindow" Height="350" Width="525"&gt; &lt;Grid&gt; &lt;local:BigList/&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>MainWindow.cs:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace LargeItemsCollection { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = new BindingViewModel(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload