HI,
i have a very slow ItemsControl with up to 5 DataGrids in it. (displays next to each other) Everytime when i update this Control my whole UI lags extremly (~10sec). Each Datagrid has ~50-400 items with predifined columns (not autogenerated). The itemsources of the grids get updated at the same time.
Here is my XAML:
<pre> <ScrollViewer Grid.Row="1">
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding Count}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding Content}" RowHeight="20" AutoGenerateColumns="False" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling">
<DataGrid.Columns>
<DataGridTextColumn Header="name" Binding="{Binding Name}" Width="100" />
<DataGridTextColumn Header="value" Binding="{Binding Value}" Width="50" />
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ScrollViewer>
And here the Code Behind:
public partial class MainWindow : Window
{
public List<Folder> Folders { get; set; }
public MainWindow()
{
InitializeComponent();
Folders = new List<Folder>();
Folders.Add(new Folder());
Folders.Add(new Folder());
this.DataContext = Folders;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Folders.ForEach(f => f.UpdateData());
}
}
public class Folder
{
private Random _rand = new Random();
public ObservableCollection<Content> Content { get; set; }
public Folder()
{
Content = new ObservableCollection<Content>();
}
public void UpdateData()
{
Content.Clear();
for(int i = 1; i <= 300; i++)
Content.Add(new Content($"C{i}", _rand.Next(1,400)));
}
}
public class Content
{
public string Name { get; set; }
public int Value { get; set; }
public Content(string name, int value)
{
Name = name;
Value = value;
}
}
Pls find also attached a full working example
here.
Any ideas how i can speed up the datagrids without blocking the whole UI?
KR Manu
What I have tried:
I have tried to replace the datagrids with listboxes but the UI is still blocking.
Well it's not blocking that long but i need a solution without blocking at all.