title: WPF DataGrid EnableColumnVirtualization="True" Raises NullReferenceException at DataGridCellsPanel.get_HasCorrectRealizedColumns()
body: <p>I have a WPF DataGrid with<code>EnableColumnVirtualization="True"</code>. The user control displays but as soon as you scroll or resize you'll receive a <code>NullReferenceException</code> at <code>DataGridCellsPanel.get_HasCorrectRealizedColumns()</code>. Setting <code>ColumnVirtualization="False"</code> corrects the issue. I've tried removing <code>EnableRowVirtualization="True"</code> ... etc thinking that maybe it was due to a combination of properties but I'm able to reproduce the issue with a very simple DataGrid:</p>
  
  <pre><code>&lt;DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="True" EnableColumnVirtualization="True"
  </code></pre>
  
  <p>Has anyone else run into this? I'm running Win7 64. Thanks all!</p>
  
  <pre><code>   at System.Windows.Controls.DataGridCellsPanel.get_HasCorrectRealizedColumns()
     at System.Windows.Controls.Primitives.DataGridCellsPresenter.SyncProperties(Boolean forcePrepareCells)
     at System.Windows.Controls.DataGridRow.SyncProperties(Boolean forcePrepareCells)
     at System.Windows.Controls.DataGridRow.PrepareRow(Object item, DataGrid owningDataGrid)
     at System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject element, Object item)
     at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
     at System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled)
     at System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized, Boolean isBeforeViewport)
     at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(IItemContainerGenerator&amp; generator, IContainItemStorage&amp; itemStorageProvider, IContainItemStorage&amp; parentItemStorageProvider, Object&amp; parentItem, Boolean&amp; hasUniformOrAverageContainerSizeBeenSet, Double&amp; computedUniformOrAverageContainerSize, Boolean&amp; computedAreContainersUniformlySized, IList&amp; items, Object&amp; item, IList&amp; children, Int32&amp; childIndex, Boolean&amp; visualOrderChanged, Boolean&amp; isHorizontal, Size&amp; childConstraint, Rect&amp; viewport, VirtualizationCacheLength&amp; cacheSize, VirtualizationCacheLengthUnit&amp; cacheUnit, Boolean&amp; foundFirstItemInViewport, Double&amp; firstItemInViewportOffset, Size&amp; stackPixelSize, Size&amp; stackPixelSizeInViewport, Size&amp; stackPixelSizeInCacheBeforeViewport, Size&amp; stackPixelSizeInCacheAfterViewport, Size&amp; stackLogicalSize, Size&amp; stackLogicalSizeInViewport, Size&amp; stackLogicalSizeInCacheBeforeViewport, Size&amp; stackLogicalSizeInCacheAfterViewport, Boolean&amp; mustDisableVirtualization, Boolean isBeforeFirstItem, Boolean isAfterFirstItem, Boolean isAfterLastItem, Boolean skipActualMeasure, Boolean skipGeneration, Boolean&amp; hasBringIntoViewContainerBeenMeasured, Boolean&amp; hasVirtualizingChildren)
     at System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1&amp; lastPageSafeOffset, List`1&amp; previouslyMeasuredOffsets, Boolean remeasure)
     at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
     at System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint)
     at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
     at System.Windows.UIElement.Measure(Size availableSize)
     at System.Windows.ContextLayoutManager.UpdateLayout()
     at System.Windows.Controls.VirtualizingStackPanel.&lt;&gt;c__DisplayClassa.&lt;InitializeViewport&gt;b__7()
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
     at System.Windows.Threading.DispatcherOperation.InvokeImpl()
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     at System.Windows.Threading.DispatcherOperation.Invoke()
     at System.Windows.Threading.Dispatcher.ProcessQueue()
     at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
     at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
     at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
     at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
     at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
     at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
     at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
     at System.Windows.Application.RunInternal(Window window)
     at System.Windows.Application.Run()
     at ....App.Main() in c:\....\obj\Debug\App.g.cs:line 0
  </code></pre>