question

Manoj-2114 avatar image
0 Votes"
Manoj-2114 asked Manoj-2114 commented

ArgumentException: "Height must be non-negative" from VirtualizingStackPanel

Hi,

We have a WPF application having a TreeView control with virtualization enabled. TreeView items keep get added(also removed) at run time.

We got an ArgumentException:"Height must be non-negative"(please see the call stack below) while tree items were added to the collection. Collection was updated from the dispatcher.

Could someone tell what could be root cause and the solution? Thanks.

Message: Did skip 41 messages. Content: An exception of type 'System.ArgumentException' occurred and was caught.


2021-03-10T12:45:34.555+01:00
Exception Messages:
ArgumentException : Height must be non-negative.

Type : System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Height must be non-negative.
Source : WindowsBase
ParamName :
TargetSite : Void set_Height(Double)
Stack Trace : at System.Windows.Rect.set_Height(Double value)
at System.Windows.Controls.VirtualizingStackPanel.ExtendViewport(IHierarchicalVirtualizationAndScrollInfo virtualizationInfoProvider, Boolean isHorizontal, Rect viewport, VirtualizationCacheLength cacheLength, VirtualizationCacheLengthUnit cacheUnit, Size stackPixelSizeInCacheBeforeViewport, Size stackLogicalSizeInCacheBeforeViewport, Size stackPixelSizeInCacheAfterViewport, Size stackLogicalSizeInCacheAfterViewport, Size stackPixelSize, Size stackLogicalSize, Int32& itemsInExtendedViewportCount)
at System.Windows.Controls.VirtualizingStackPanel.IsExtendedViewportFull()
at System.Windows.Controls.VirtualizingStackPanel.ShouldItemsChangeAffectLayoutCore(Boolean areItemChangesLocal, ItemsChangedEventArgs args)
at System.Windows.Controls.VirtualizingStackPanel.ShouldItemsChangeAffectLayoutCore(Boolean areItemChangesLocal, ItemsChangedEventArgs args)
at System.Windows.Controls.VirtualizingStackPanel.ShouldItemsChangeAffectLayoutCore(Boolean areItemChangesLocal, ItemsChangedEventArgs args)
at System.Windows.Controls.VirtualizingStackPanel.ShouldItemsChangeAffectLayoutCore(Boolean areItemChangesLocal, ItemsChangedEventArgs args)
at System.Windows.Controls.VirtualizingPanel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)
at System.Windows.Controls.Panel.OnItemsChanged(Object sender, ItemsChangedEventArgs args)
at System.Windows.Controls.ItemContainerGenerator.OnItemAdded(Object item, Int32 index)
at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args, Int32 adjustedOldIndex, Int32 adjustedNewIndex)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)




windows-wpf
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@Manoj-2114 . Is there a reproducible scenario that we can use? Is this an issue with WPF running on .NET Core 3 or .NET Framework 4.8?

0 Votes 0 ·

Hi HuiLiu, Any update on this topic? Thanks.

1 Vote 1 ·

Hi HuiLiu,
This issue is reported from the application running on .NET Framework 4.8.
I got a sample code from web which reproduces this issue. Code is attached.
To reproduce the issue, run this sample application and scroll to the bottom of the window(click and hold scrollbar thumb and drag to bottom. Repeat if required). Application terminates after some seconds. Retry few times to reproduce. Exception can be found in the event log.

140178-mainwindowxamlcs.txt140196-mainwindowxamlcs.txt140233-mainwindowxaml.txt


0 Votes 0 ·

0 Answers