1

My custom control should contains 1000000+ items. I've implemented the custom control based on ItemsControl. The source XAML of the control is:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:behaviors="clr-namespace:MyTestApplication.Behaviors"
                    xmlns:helpers="clr-namespace:MyTestApplication.Helpers"
                    xmlns:local="clr-namespace:MyTestApplication.Controls"
                    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">

    <Style TargetType="{x:Type local:RowsWrapperControl}">

        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling" />
        <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True" />

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:RowsWrapperControl}">
                    <ScrollViewer x:Name="PART_ItemsScrollViewer"
                                  Margin="{TemplateBinding Margin}"
                                  Background="{TemplateBinding Background}"
                                  BorderBrush="{TemplateBinding BorderBrush}"
                                  BorderThickness="{TemplateBinding BorderThickness}"
                                  CanContentScroll="True"
                                  HorizontalScrollBarVisibility="Disabled"
                                  Padding="{TemplateBinding Padding}"
                                  VerticalScrollBarVisibility="Hidden">
                        <i:Interaction.Behaviors>
                            <behaviors:ScrollViewerOffsetBehavior VerticalOffset="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=VerticalScrollOffset, Mode=OneWay}" />
                        </i:Interaction.Behaviors>
                        <ItemsPresenter />
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

</ResourceDictionary>

The virtualizing works good, but scrolling works only item-by-item, not pixel-by-pixel. I tried to set the CanContentScroll property to False , but it breaks the visualization. I found some helpful information here and here, but it takes no effect for me.

Any idea how to turn on the smooth scrolling?

I have .Net 4.5 installed on my PC, but the target platform is .Net 4.0.

UPDATE: The solution was found here.

Community
  • 1
  • 1
  • Is it possible to upgrade the target to 4.5? I'd point you at `VirtualizingPanel.ScrollUnit="Pixel"` (http://stackoverflow.com/questions/19013841/wpf-datagrid-rowdetail-is-cut-off/19014608#19014608) but I don't think it will help in your case. – Chris Dec 28 '13 at 11:15
  • Unfortunately no. The target platform can be only .Net 4.0 – Mykhailo Bratukha Dec 28 '13 at 16:39

1 Answers1

0

do you have a simple list of data or tree alike data structure? What does your custom control do or should do? Only TreeView in WPF .NET 4.0 supports scrolling by pixels. A ListBox scrolls by items/units. Derivate your custom control from TreeView and you should do fine. Or wrap it in a TreeView. TreeView may also display simple list of data without hierarchical structure. I actually ment many people telling me they place their lists in TreeView just to have that pixel scrolling effect because it looks better than jumping over items/units/data however you call it.

Try it out :) I could place this as comment since its too large but if it works mark it as answer.

dev hedgehog
  • 8,698
  • 3
  • 28
  • 55