Why VirtualizingStackPanel.IsVirtualizing in silverlight datagrid threw an exception?

272 views Asked by At

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 ---

1

There are 1 answers

6
Nkosi On

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">