Child elements of scrollviewer preventing scrolling with mouse wheel?

You can also create a behavior and attach it to the parent control (in which the scroll events should bubble through). // Used on sub-controls of an expander to bubble the mouse wheel scroll event up public sealed class BubbleScrollEvent : Behavior<UIElement> { protected override void OnAttached() { base.OnAttached(); AssociatedObject.PreviewMouseWheel += AssociatedObject_PreviewMouseWheel; } protected override … Read more

Accessing the ScrollViewer of a ListBox from C#

you can try this little helper function usage var scrollViewer = GetDescendantByType(yourListBox, typeof(ScrollViewer)) as ScrollViewer; helper function public static Visual GetDescendantByType(Visual element, Type type) { if (element == null) { return null; } if (element.GetType() == type) { return element; } Visual foundElement = null; if (element is FrameworkElement) { (element as FrameworkElement).ApplyTemplate(); } for … Read more

why setting ScrollViewer.CanContentScroll to false disable virtualization

“ScrollViewer currently allows two scrolling modes: smooth pixel-by-pixel scrolling (CanContentScroll = false) or discrete item-by-item scrolling (CanContentScroll = true). Currently WPF supports UI virtualization only when scrolling by item. Pixel-based scrolling is also called “physical scrolling” and item-based scrolling is also called “logical scrolling”.” Virtualization requires an item-based scrolling so it can keep track of … Read more

How can I get ScrollViewer to work inside a StackPanel?

This was bugging me for a while too, the trick is to put your stackpanel within a scrollviewer. Also, you need to ensure that you set the CanContentScroll property of the scroll viewer to True, here’s an example: <ScrollViewer Grid.Row=”1″ Margin=”299,12,34,54″ Name=”ScrollViewer1″ VerticalScrollBarVisibility=”Auto” HorizontalScrollBarVisibility=”Auto” Height=”195″ CanContentScroll=”True”> <StackPanel Name=”StackPanel1″ OverridesDefaultStyle=”False” Height=”193″ Width=”376″ VerticalAlignment=”Top” HorizontalAlignment=”Left”></StackPanel> </ScrollViewer>