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:

enter image description here

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.

  • Can it be easier to create an image in code and only then display it in a single piece? - user227049
  • @FoggyFinder, supposed to print. There will still be text in each square. Print quality will be poor. - Salnik
  • one
    Too much load on ItemsControl . will slow down in any case. It is necessary to display on the Canvas . Yes, and you can show the user one thing, and print another, this is me about low quality. - Bulson
  • @Bulson tried, by transfer it hangs also. Is it somehow working with DataGrid ? - Salnik
  • We don’t know what is under the hood of the DataGrid , 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

0