Skip to content

WPF TreeView, virtualization, scroll, freeze #1962

Closed

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


Using VirtualizingStackPanel can freeze the execution.
Steps to reproduce:

  1. Build a WPF application with TreeView, VirtualizingStackPanel , expanded nodes, release version,
  2. start the exe,
  3. scroll to the end of the tree,
  4. click on the scroll bar at the top and keep the left mouse button pressed.
    The application freeze.

To reproduce try the following demo.:

' XAML:

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<TreeView ItemsSource="{Binding View}"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
VirtualizingPanel.ScrollUnit="Item">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:Data}" ItemsSource="{Binding Childs}">
<Label Content="{Binding Info}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
</Grid>
</Window>

' ViewModel:

Imports System.Collections.ObjectModel
Imports System.ComponentModel

Public Class ViewModel

Public Sub New()
For i = 1 To 100
Dim d As New Data With {. Info = $"Node {i:000}"}
For k = 1 To 10
Dim c As New Data With {. Info = $"Child {i:000} {k:000}"}
For l = 1 To 10
c.Childs.Add(New Data With {. Info = $"Grandchild {i:000} {k:000} {l:000}"})
Next
d.Childs.Add(c)
Next
col. Add(d)
Next
cvs. Source = col
End Sub

Private col As New ObservableCollection(Of Data)
Private cvs As New CollectionViewSource

Public ReadOnly Property View As ICollectionView
Get
Return cvs. View
End Get
End Property

End Class

' Data class

Imports System.Collections.ObjectModel

Public Class Data
Public Property Info As String
Public Property Childs As New ObservableCollection(Of Data)
End Class


Original Comments

(no comments)


Original Solutions

(no solutions)

Activity

  1. self-assigned this
    on Oct 1, 2019
  2. added
    Bug
    📭 waiting-author-feedback
    on Oct 4, 2019
  3. grubioe commented on Oct 4, 2019

    @grubioe
    Contributor

    Can you provide what version of Windows and .NET you are running? Thanks

  4. added and removed
    📭 waiting-author-feedback
    on Oct 8, 2019
  5. iihnat commented on Oct 11, 2019

    @iihnat

    Andriy,

    We have similar problem.
    Try VirtualizingPanel.VirtualizationMode="Standard". This way scrolling becomes a bit slower but at least application is not freezing in our case.

  6. assigned and unassigned on Oct 16, 2019
  7. grubioe commented on Oct 18, 2019

    @grubioe
    Contributor

    @AndriyGlu to help with prioritization can you provide more details on what is your business scenario where this issue surfaces? What is the application, number of users and details related to the business impact of this issues? Thank you

  8. grubioe commented on Oct 21, 2019

    @grubioe
    Contributor

    Thanks @AndriyGlu - what is the name of the encyclopedia product? Can you email me more specific information, the email is available from my GitHub profile.

  9. 27 remaining items

  10. ghost removed this from the 5.0 milestone on Nov 25, 2019
  11. ju2pom commented on Jan 7, 2020

    @ju2pom

    Hi @SamBent,
    First thank you for investing time and energy in this community issue.
    We have the same symptom in one of our internal software (>1000 users), this time using a ListView with virtualization and grouping (groups can be expanded/collapsed). I have created an stf file and a memory dump (>2Go). How can I give them to you?
    Would it be possible to test a "beta" or unofficial build of .NetFramework to check if your recent fix is effective in our scenario?

  12. SamBent commented on Jan 7, 2020

    @SamBent
    Contributor

    @ju2pom The best thing to do is open a case with Microsoft Customer Support. That will create a workspace in which we can trade large files securely and privately. If it's our bug (as this surely is), you don't get charged. Include the following information, to get it routed in the right direction
    Product: .NET Framework 4.x
    Category: Class Library Namespaces\System.Windows (WPF)

    For the preview fix, you'll want to prepare a test machine that you can afford to rebuild; the private installation might leave your machine in a non-serviceable state (where Windows Update can't install new patches). And I'll need to know which version of .NET is installed, and the bitness (x86 v. x64).

    As you probably already knew, scrolling in ListView + grouping (with expand/collapse) is handled by the same code as TreeView. So my fix will resolve your problem, if it's one of the "two independent issues" described earlier.

  13. SamBent commented on Jan 27, 2020

    @SamBent
    Contributor

    For .NET 4.6+, the fix has been released for many OS (others to follow this week). For details see the announcement.
    For .NET Core 3.1.2, the fix is PR #2271.

    If you are still seeing hangs after installing this fix, please open a new issue (and link to this issue, to aid discovery).

  14. yingDev commented on Jan 30, 2021

    @yingDev

    In my case, it is related to UseLayoutRounding="True". changed it to "False" at some level in the tree then the bug disappeared.

     <Style TargetType="VirtualizingStackPanel">
           <Setter Property="UseLayoutRounding" Value="False"/>
       </Style>

    dotnet --version: 5.0.200-preview.20614.14

  15. ghost locked as resolved and limited conversation to collaborators on Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

.NET FrameworkBugarea-VirtualizingStackPanelnetfx-servicing-approved

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions