我有一个图形项和矩阵项。图形项目是画布,我画椭圆和线。在矩阵项I中包含矩阵。我使用了这个库(xmlns:dg 2d =“clr-namespace:DataGrid 2DLibrary; assembly= DataGrid 2DLibrary”)(http://www.mediafire.com/?tm1arm230rr1tgi)将我的二维矩阵绑定到datagrid。但我注意到,在我点击矩阵项目之前,只要程序刚刚开始,我的意思是首先我与图形工作。Canvas绘制速度非常快,但在我点击矩阵项和itemsource后,当我再次返回图形时,它绘制得非常慢。另外,我注意到itemssource之后有很多内存。
在这段代码中,我尝试空ItemsSource并清除内存
MainWindow.xaml.cs
private void MatrixData(object sender, RoutedEventArgs e)
{
if (MatrixMenu.IsChecked)
{
if (DrawingCanvas_Undirected.Visibility == Visibility.Visible || DrawingCanvas_Directed.Visibility == Visibility.Visible)
{
GraphItem.Visibility = Visibility.Visible;
}
MatrixItem.Visibility = Visibility.Collapsed;
MatrixAdj.ItemsSource2D = null;
MatrixInc.ItemsSource2D = null;
MatrixMenu.IsChecked = false;
GC.Collect();
}
MainWindow.xaml
<Grid x:Name="MatrixItem" Visibility ="Collapsed">
<Grid.RowDefinitions>
<RowDefinition Height="149*"/>
<RowDefinition Height="285*"/>
</Grid.RowDefinitions>
<Canvas>
<dg2d:DataGrid2D x:FieldModifier="public" x:Name="MatrixAdj"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
Canvas.Left="411" Canvas.Top="20"
Width="350" Height="289"
AlternationCount="2"
UseModifiedDataGridStyle="True"
ItemsSource2D="{Binding Int2DList}"
RowBackground="White"
AlternatingRowBackground="#ebebeb"
Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Center" />
</Canvas>
<Canvas Margin="4,2,-4,265" Grid.RowSpan="2">
<dg2d:DataGrid2D x:FieldModifier="public" x:Name="MatrixInc"
Canvas.Left="19" Canvas.Top="20"
Width="350" Height="289"
AlternationCount="2"
UseModifiedDataGridStyle="True"
ItemsSource2D="{Binding Int2DList}"
RowBackground="White"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
AlternatingRowBackground="#ebebeb"
Background="Transparent" Grid.RowSpan="2" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Canvas>
</Grid>
所以问题是:点击矩阵项后如何保存画布绘制速度?
1条答案
按热度按时间dhxwm5r41#
当datagrid不活动时删除它(从canvas子元素中删除datagrid)