wpf datagrid render performance (custom grid control) -
**please see updates question below
i trying use datagrid in wpf application finding performance unbearable.
i binding dataset 100 rows , 15 columns , sort of scrolling or column width resizing paints extremely slowly.
i recall old winforms datagridview had poor performance when cell borders turned on, turning off gridlines in it's wpf counterpart has no effect.
the window grid:
<window x:class="gridperformancetest.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <datagrid itemssource="{binding}" autogeneratecolumns="true" enablecolumnvirtualization="true" enablerowvirtualization="true" virtualizingstackpanel.isvirtualizing="true" virtualizingstackpanel.virtualizationmode="recycling" background="{x:null}" borderbrush="{x:null}" issynchronizedwithcurrentitem="false" borderthickness="0" rowheight="15" gridlinesvisibility="none" horizontalgridlinesbrush="{x:null}" verticalgridlinesbrush="{x:null}" columnheaderheight="15"/> </grid>
how populating data:
public partial class mainwindow : window { public mainwindow() { initializecomponent(); datasource source = new datasource(); dataset ds = new dataset(); ds.tables.add(source.execute("select * tbl_users")); this.datacontext = ds.tables[0]; } }
edit:
so because have had no luck datagrid, i'm sure has many more features looking right (simply display plain text , select data copy/paste) decided try , work on own.
this first shot @ custom user control, have found source of poor performance...the grid.
if write control grid splitters columns , stackpanels contain row data, scrolling through rows flawless - used 'ol winforms datagrid.
grid control code:
public partial class customgridcontrol : usercontrol { public customgridcontrol() { initializecomponent(); (int = 0; < 20; i++) { columndefinition col = new columndefinition(); col.width = new gridlength(75); _rootgrid.columndefinitions.add(col); stackpanel pnl = new stackpanel(); pnl.orientation = orientation.vertical; (int x = 0; x < 1000; x++) { textblock blk = new textblock(); blk.foreground = brushes.black; blk.text = "row: " + x.tostring() + " col: " + i.tostring(); pnl.children.add(blk); } grid.setcolumn(pnl, i); _rootgrid.children.add(pnl); gridsplitter splitter = new gridsplitter(); splitter.width = 2; splitter.borderbrush = brushes.black; grid.setcolumn(splitter, i); grid.setrowspan(splitter, 1000); _rootgrid.children.add(splitter); } }
and xaml:
<usercontrol x:class="customgrid.customgridcontrol" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="300"> <grid > <scrollviewer> <grid x:name="_rootgrid" background="aqua"/> </scrollviewer> </grid>
when try , drag 1 of splitters, performance horrible, standard wpf datagrid.
now know not doing virtualization optomize performance or performance stackpanels still 100x better.
to update question - know if has ideas of how handle columns in type of panel allow same gridsplitter type functionality columns.
any links custom panels/grids appreciated well.
as suggested here, can bit of performance improvement setting 'enablerowvirtualization' , 'enablecolumnvirtualization' instead of virtualizingstackpanel.*
properties.
you can improve things setting fixed column widths.
Comments
Post a Comment