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 .
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.