MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

Expanders in ListView broken when using VirtualizingPanel

Open LePtitDev opened this issue 5 years ago • 7 comments

Since version 3.2.0, collapse an expander in ListView hide items after this expander. I configured VirtualizingPanel in the list view.

Demonstration of the bug

capture

Sample of the bug

I created a repository on GitHub here with 2 projects:

  • [email protected] that use MaterialDesignThemes at version 3.1.3
  • [email protected] that use MaterialDesignThemes at version 3.2.0 Theses projects contain same code but with different MaterialDesignThemes versions.

There is no bug with MaterialDesignThemes at version 3.1.3.

In MainWindow.xaml when I remove VirtualizingPanel lines, it work fine.

13          <ListView x:Name="ListView" ItemsSource="{Binding ElementName=Control, Path=CollectionView}"
14                    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
15 -                  VirtualizingPanel.IsVirtualizingWhenGrouping="True"
16 -                  VirtualizingPanel.IsVirtualizing="True"
17 -                  VirtualizingPanel.IsContainerVirtualizable="True"
18                    Padding="0"
19                    SelectionMode="Single">

LePtitDev avatar Dec 08 '20 13:12 LePtitDev

Very well written bug. Thank you!

For historical reference here is the zip of the above reference projects. MaterialDesignSamples-main.zip

Keboo avatar Dec 08 '20 15:12 Keboo

I'm curiously having some of the same behavior in a DataGrid with virtual rows and grouping. If I use snoop then it seems like the next Group's DataContext gets set to DisconnectedItem: https://source.dot.net/#PresentationFramework/System/Windows/Data/BindingExpressionBase.cs,71f3b982041c21ce,references

jespersh avatar Jan 27 '21 12:01 jespersh

I've spent some time tracking this down, and it seems like the VirtualizingStackPanel does not play nice with 'ScaleY' transforms. It seems like there's a bug in VirtualizingStackPanel where it thinks that items that appear after the scaled item are no longer visible, so it removes them.

I've fixed this locally by removing the ScaleY transforms in MaterialDesignTheme.Expander.xaml. Just search for 'ScaleY' and you'll find three DoubleAnimation elements with TargetProperty="(ScaleTransform.ScaleY)". Comment those out and the problem goes away.

This has the side effect of removing the shrink effect when you collapse an item. That honestly doesn't bother me, but I didn't want to create a Pull Request as I'm not sure if that's acceptable. Also, there may be a better solution that retains the shrinking effect that I'm not aware of.

It appears as if this was introduced with these changes: https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/pull/1986

EDIT: You can see the changes that I made here: https://github.com/philpowers/MaterialDesignInXamlToolkit/commit/12f24c980c2d23ab9cb69a48b77cc7de54cfe2ba

philpowers avatar Feb 27 '21 08:02 philpowers

Hey @w-syss, since you worked on that and it might be fresh in your memory still, would you take a look at this to see if you can make sense of it?

Much appreciated

jespersh avatar Feb 27 '21 08:02 jespersh

Hi, i will take a look at this.

w-syss avatar Mar 01 '21 10:03 w-syss

This is still broken, any suggestions how to fix it?

tomasfil avatar Apr 06 '22 08:04 tomasfil

I tried adding the code from the author to the demo application (latest from master branch) to see if I could repro and fix the issue. I am however not able to reproduce the issue. Has this issue been fixed by some other fix?

I have a branch available here with the code added to the demo application: https://github.com/nicolaihenriksen/MaterialDesignInXamlToolkit/tree/fix2188

@w-syss you indicated that you were going to look at it. Do you have an update? if you can remember that far back :-)

nicolaihenriksen avatar Jul 06 '22 10:07 nicolaihenriksen

This issue is marked stale because it has been open 30 days with no activity. Remove stale label or update the issue, otherwise it will be closed in 14 days.

github-actions[bot] avatar Apr 20 '23 18:04 github-actions[bot]

This issue was closed because it has been stalled for 14 days with no activity.

github-actions[bot] avatar May 05 '23 01:05 github-actions[bot]