0

i added VirtualizingStackPanel in my datagrid for on-demand load records to get rid of too long loading time taken to display all the records.

<sdk:DataGrid VirtualizingStackPanel.VirtualizationMode="Recycling" VirtualizingStackPanel.IsVirtualizing="True" AutoGenerateColumns="False" 
                          HorizontalAlignment="Center" Name="dgrGrid"  Width="430" Height="270" Grid.Row="1" Margin="10,10,10,10" Loaded="dgrGrid_Loaded">

but when i tried to load data on the datagrid, got this error...can someone point me where to correct this error? thanks in advance.

{System.Windows.Markup.XamlParseException: Set property 'System.Windows.Controls.VirtualizingStackPanel.IsVirtualizing' threw an exception. [Line: 37 Position: 123] ---> System.NotSupportedException: Cannot set read-only property 'System.Windows.Controls.VirtualizingStackPanel.IsVirtualizing'. at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value) at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue) --- End of inner exception stack trace ---

jeliey
  • 21
  • 1
  • 1
  • 6

1 Answers1

0

You should remove the VirtualizingStackPanel.IsVirtualizing="True" as the exception message states that it is a read-only property. SL datagrid uses already uses virtualization for performance optimization, so you just need to set the virtualization mode you want it to utilize.

Your DataGrid will then look like...

<sdk:DataGrid 
    VirtualizingStackPanel.VirtualizationMode="Recycling"   
    AutoGenerateColumns="False" 
    HorizontalAlignment="Center" 
    Name="dgrGrid"  
    Width="430" 
    Height="270" 
    Grid.Row="1" 
    Margin="10,10,10,10" 
    Loaded="dgrGrid_Loaded">
Nkosi
  • 235,767
  • 35
  • 427
  • 472
  • hi @Nkosi, i have deleted `VirtualizingStackPanel.IsVirtualizing="True"` but seems like my datagrid loading time is still same. i have to wait almost 5 minutes to get 2000 records. after added this in xaml file, should i add any other function/process at the back end code? – jeliey Apr 28 '16 at 03:42
  • 2000 records in a data grid is alot and will slow down your app. you should consider paging your data server side and downloading it in chunks. – Nkosi Apr 28 '16 at 03:47
  • yup, thats why i want to do this virtualizing thing like a lazy loading. so it should display a 50 first records. and when user scroll down the mouse, the datagrid will load the next 50 records. can we achieve this using virtualizing? – jeliey Apr 28 '16 at 03:59
  • The virtualization is for the items currently in the Control. Lazy loading data is more of an architecture/design issue coupled with your UI. Load first page (50) monitor scrollbar of grid. when it hits the bottom (or some pre-defined percentage down) check server for more record. If there more then down load and add to grid. you will eventually end up with the same problem of all items are eventually loaded into the grid. – Nkosi Apr 28 '16 at 04:05
  • yes @Nkosi, that is exactly what im looking for right now. i dont want to display the records all at once since it will slow down the performance, but still have to display some at a time. and load the next records, when user need them...can u help me? or may be any example to do this? – jeliey Apr 28 '16 at 04:13
  • Try taking a look at this question and the provided answer [How to implement a lazy loaded Silverlight data grid without using paging](http://stackoverflow.com/a/11931522/5233410) – Nkosi Apr 28 '16 at 04:49