绘制网格的最快方法是c#
目前,我正在使用WPF窗口绘制一个“单元格”网格(每个单元格都是唯一的-不同的颜色、边框等),并使用网格将单元格列表绑定到ItemsControl ItemSource …这很慢,真的很慢。渲染需要几秒钟。有没有更快的方法可以画出这样的网格绘制网格的最快方法是c#,c#,wpf,C#,Wpf,目前,我正在使用WPF窗口绘制一个“单元格”网格(每个单元格都是唯一的-不同的颜色、边框等),并使用网格将单元格列表绑定到ItemsControl ItemSource …这很慢,真的很慢。渲染需要几秒钟。有没有更快的方法可以画出这样的网格 <Window.Resources> <DataTemplate x:Key="CellTemplate"> <local:CellImage Width="10" Height="10" CellP
<Window.Resources>
<DataTemplate x:Key="CellTemplate">
<local:CellImage Width="10" Height="10" CellProperty="{Binding}"></local:CellImage>
</DataTemplate>
<DataTemplate x:Key="WholeTemplate">
<ItemsControl ItemsSource="{Binding}" ItemTemplate="{StaticResource CellTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</Window.Resources>
<Grid Name="WholeGrid">
<StackPanel>
<ItemsControl x:Name="WholeGrid" ItemTemplate="{DynamicResource WholeTemplate}">
</ItemsControl>
</StackPanel>
</Grid>
以及约束力:
List<List<Cell>> lsts = new List<List<Cell>>();
WholeGrid.ItemsSource = lsts;
List lsts=new List();
WholeGrid.ItemsSource=lsts;
像这样将堆栈面板更改为虚拟化堆栈面板
ItemsControl ItemsSource="{Binding}" ItemTemplate="{StaticResource CellTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
ItemsControl ItemsSource=“{Binding}”ItemTemplate=“{StaticResource CellTemplate}”>
然后,它将只画那些可见的项目,应该快得多,当你滚动它应该画尽可能多的需要 使用
DataGrid
怎么样?我试过DataGrid,它也有类似的问题。只是花了很长时间渲染你能发布你的代码吗?您是用XAML创建网格还是用C#手动构建网格?发布您的代码或创建一个略显粗糙的下拉列表…但我在中添加了一些代码(问题不是那么复杂吗?)