sbaeumlisberger / VirtualizingWrapPanel

Implementation of a comprehensive VirtualisingWrapPanel for WPF
MIT License
254 stars 35 forks source link

Null reference #9

Closed strigefleur closed 4 years ago

strigefleur commented 4 years ago

Hello. I'm using latest NuGet package version, just replaced default WrapPanel with the code below and getting exception. ExclusionsView is a CollectionViewSource.

...
xmlns:vwp="clr-namespace:WpfToolkit.Controls;assembly=VirtualizingWrapPanel"
...
<ItemsControl ItemsSource="{Binding ExclusionsView}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <vwp:VirtualizingWrapPanel Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth}"
                                       FlowDirection="RightToLeft" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>

    <ItemsControl.Template>
        <ControlTemplate>
            <ScrollViewer Style="{StaticResource LeftScrollViewer}">
                <ItemsPresenter />
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>

    <!-- complex item template here -->
</ItemsControl>

Getting this at the very start of app (before UI appears):

An unhandled exception of type 'System.NullReferenceException' occurred in System.Private.CoreLib.dll
Object reference not set to an instance of an object.
juner commented 4 years ago

Maybe VirtualizingPanelBase#ScrollOwner isn't set?

Is the Dependency property ScrollViewer.CanContentScroll set to False? \ If False, VirtualizingPanelBase#ScrollOwner is not set.

strigefleur commented 4 years ago

Neither removing ScrollViewer entirely nor setting CanContentScroll="True" changed anything.

sbaeumlisberger commented 4 years ago

Hello

indeed there is an issue in combination with ItemsControl since version 1.5.1. In version 1.5.0 everything works fine.

But still be aware that the ItemsControl does not support virtualization out of box. Therefore the NuGet package includes a VirtualizingItemsControl. If you nevertheless want to use the ItemsControl you have to add ScrollViewer.CanContentScroll="true" and keep the ScrollViewer in the control template.

The next time I release a NuGet package, I will provide a fix even if the VirtualizingWrapPanel should not be used like that.

strigefleur commented 4 years ago

Aha, nice mention on VirtualizingItemsControl, thank you. Waiting for the next release.

sbaeumlisberger commented 4 years ago

This fix is released with Version 1.5.3 just now. https://www.nuget.org/packages/VirtualizingWrapPanel/1.5.3