8000 When Popup (combobox, tooltip, menu item, etc) is shown within an app with a DataGrid, the DataGrid becomes slow and less responsive. · Issue #9881 · dotnet/wpf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

When Popup (combobox, tooltip, menu item, etc) is shown within an app with a DataGrid, the DataGrid becomes slow and less responsive. #9881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brswan opened this issue Oct 2, 2024 · 6 comments
Labels
Investigate Requires further investigation by the WPF team. Performance Performance related issue

Comments

@brswan
Copy link
brswan commented Oct 2, 2024

Description

When Popup (combobox, tooltip, menu item, etc) is shown within an app with a DataGrid, the DataGrid becomes slow and less responsive. When debugging this problem, we output properties from before and after the popup was shown. It appears the datagrid has several properties that get changed when only a popup is shown. Properties of interest include SizeToContentV, HasStarCellsU, HasGroup3CellsInAutoRows.

Screenshot 2024-10-02 134404

I ran a performance profiler and can see that after the popup is shown the Layout time increases by a major factor as well as the frame rate drops substantially.

Screenshot 2024-10-02 142645

I have tried to fix the datagrid column width and row height to no avail. I have also overridden the cell template with fixed size values and this did not work either.

datagrid-02

DataGridTest.zip

Reproduction Steps

  • Create an app with a combobox and datagrid (see attachment).
  • Run the app and vertically scroll. Scrolling will be smooth without lag.
  • Open the combobox to show the items panel. You do not need to select an item - the panel just needs to be shown
  • Close combobox panel
  • Vertically scroll the datagrid and you will see lag (it may be slight lag but it is an indicator of the problem)

Apps with more complex UIs will display this issue more apparently.

Included app has a button Export that will export all properties of the app. You can export before following the steps above. Then export again once slowness occurs and you will see properties are changed from before and after combobox items are displayed. Please see screen shot from Description for comparison.

Expected behavior

Datagrid should behave the same way before a Popup (combobox, tooltip, menu item, etc) is shown and after.

Actual behavior

Datagrid is responsive before a Popup (combobox, tooltip, menu item, etc) is shown. After the popup is shown, datagrid slows.

Regression?

Problem exists in NET6 and NET8

Known Workarounds

None at this time

Impact

Datagrid in the app becomes slow and sluggish to use. Our app is a real-time app that requires the datagrid to be responsive to user input.

Configuration

Windows 11 Pro 23H2 OS Build 22631.4169
Visual Studio 2022 Version 17.9.6
x64

Other information

No response

@h3xds1nz
Copy link
Member
h3xds1nz commented Oct 2, 2024

This is because of #5807, GridView for example had one more speciality (#9181) but DataGrid just compensates it with actually having a lot of controls you need to have peers for.

@brswan
Copy link
Author
brswan commented Oct 2, 2024

@h3xds1nz Thanks for pointing this out. Do you know if Microsoft is addressing this?

@brswan
Copy link
Author
brswan commented Oct 2, 2024

It appears I was able to solve my data grid sluggish issue by making my own DataGrid class and returning null in OnCreateAutomationPeer. I'm not sure what ramifications this may have but it appears to work,.

    public class MyDataGrid : DataGrid
    {
        public MyDataGrid()
        {
        }


        protected override AutomationPeer OnCreateAutomationPeer()
        {
            return null;
            //return base.OnCreateAutomationPeer();
        }
    }

@brswan
Copy link
Author
brswan commented Oct 3, 2024

I found a solution that works for my problem. I had to override the Windows class. From there you override the OnCreateAutomationPeer() method.

 public class CustomWindowAutomationPeer : FrameworkElementAutomationPeer
 {
     public CustomWindowAutomationPeer(FrameworkElement owner) : base(owner) { }

     protected override string GetNameCore()
     {
         return "CustomWindowAutomationPeer";
     }

     protected override AutomationControlType GetAutomationControlTypeCore()
     {
         return AutomationControlType.Window;
     }

     protected override List<AutomationPeer> GetChildrenCore()
     {
         return new List<AutomationPeer>();
     }
 }

In your custom Window class add

 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
   {
       return new CustomWindowAutomationPeer(this);
   }

@himgoyalmicro himgoyalmicro added Performance Performance related issue Investigate Requires further investigation by the WPF team. labels Oct 4, 2024
@Tiptup300
Copy link
Tiptup300 commented Feb 17, 2025

I am also experiencing this issue.

Specifically having a PopUp on the screen greatly hurts the performance of my datagrid with roughly 900-1200 rows and maybe 40 columns. It runs well until the PopUp first appears.

@eric-yr-yang
Copy link
eric-yr-yang commented May 7, 2025

I encountered the same issue with ListView: the initial response is fast, but after any control pops up, the response delay increases sharply and becomes irreversible. Even after running for a long time, it does not recover.

Referring to the above, overriding the OnCreateAutomationPeer method can solve this problem.

I don’t know why such a performance issue occurs, nor do I understand whether overriding this method might lead to new problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team. Performance Performance related issue
Projects
None yet
Development

No branches or pull requests

5 participants
0