MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

DialogHost Show performance issues when using datagrid

Open stany9g opened this issue 3 years ago • 9 comments

DialogHost Show is having a performance issue when switching between two dialogs that contain a DataGrid. Tested on two computers.

Steps to reproduce:

  1. Button A -> DialogA (first init slow)
  2. Button A -> DialogA (no problem, fast)
  3. Button B -> DialogB (lags)
  4. Button B -> DialogB (no problem, fast) ...
  5. Button A -> DialogA (lag)
  6. Button B -> DialogB (lag)
  7. Button A -> DialogA (lag)
  8. Button B -> DialogB (lag ...

Test Repo created here: https://github.com/stany9g/DataHostDemo

stany9g avatar Jan 13 '21 10:01 stany9g

Attaching zip for historical reference. DataHostDemo-master.zip

Keboo avatar Jan 16 '21 06:01 Keboo

Can confirm that I am able to replicate from the attached project. I believe the issue comes down to needing to know the target size of the content in order for the animation to work correctly. This problem gets compounded by the DataGrid wanting to know its maximum size so it can virtualize its elements.

I would suspect that a fix would involve manually measuring the control for the dialog before actually showing the dialog so that the animation can know the desired target size.

Keboo avatar Jan 16 '21 06:01 Keboo

@Keboo I did a little more investigation about the suggested fix and not sure if it is the right suspect.

  1. I tried to remove the animation from the style, dit not help
  2. A little debugging where I found that the "lag" happens when DialogContent = content; this line lags even though the content has set the actual sizes.

stany9g avatar Jan 18 '21 12:01 stany9g

@Keboo @stany9g When giving a fixed Width and Height to the parent Grid element, the lag disappears.

@stany9g You could also defer the collection loading to an async Initialize method on the dialogviewmodel and setting the ItemsSource binding IsAsync="True" on the datagrid for better decoupling of UI thread and logic.

MichelMichels avatar Jan 23 '21 10:01 MichelMichels

@MichelMichels so for other UserControls need to set fixed Width and Height properties to show dialogs without any lags? Should they be equivalent to each other when need to show different dialogs?

Erapchu avatar Jan 26 '21 03:01 Erapchu

@Erapchu as @Keboo mentioned, the lag has to do with the datagrid trying to calculate it's width and height.

My guess would be that the datagrid control has issues with virtualizing the rows when no static height is set and also a problem with rendering the columns when no static width is set.

I don't know if other controls behave like this.

MichelMichels avatar Jan 26 '21 06:01 MichelMichels

Hello @MichelMichels @Keboo , has there been any progress regarding the performance issues on DialogHost startup? Can you let me know if there is any progress?

saklanmazozgur avatar Apr 15 '22 11:04 saklanmazozgur

I don't know if this is a problem that's resolvable in the dialoghost control. It's a year ago that I took a look at this issue.

MichelMichels avatar Apr 15 '22 11:04 MichelMichels

Thank you for answer @MichelMichels

saklanmazozgur avatar Apr 15 '22 12:04 saklanmazozgur