Hello.
Trying to bind a two-dimensional array of colors.
I do it like this:
<DataTemplate x:Key="Rect"> <Border BorderBrush="Black" BorderThickness="1" Background="{Binding Path=., Converter={StaticResource ColorToBrushConverter}}" Width="10" Height="10"/> </DataTemplate> ... <ScrollViewer HorizontalScrollBarVisibility="Auto"> <ItemsControl ItemsSource="{Binding Colors}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding}" ItemTemplate="{DynamicResource Rect}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer> And ViewNodel:
ObservableCollection<ObservableCollection<Color>> colors = new ObservableCollection<ObservableCollection<Color>>(); public ObservableCollection<ObservableCollection<Color>> Colors { get { return colors; } } colors.Clear(); for (int y = 0; y < height; y++) { ObservableCollection<Color> level = new ObservableCollection<Color>(); for (int x = 0; x < width; x++) { level.Add(pixels[y * width + x]); } colors.Add(level); } Those. the result is the following picture:
When the loop is executed, the UI hangs, and for a long time and tightly. Everywhere and everywhere they talk about VirtualizingStackPanel , but it did not help.
With DataGrid virtualization worked for me, but now the task is complicated by the binding of a two-dimensional array.
How to solve the hang problem? Or how to bind an array to a DataGrid , but also without hanging?
PS: tricks with OnRender and Visal not suitable. Passed through. Not that.

ItemsControl. will slow down in any case. It is necessary to display on theCanvas. Yes, and you can show the user one thing, and print another, this is me about low quality. - BulsonDataGrid? - SalnikDataGrid, because he’s a specialist in data output a priori unknown to a large amount of data, i.e. maybe he has some kind of special buffer. - Bulson