Posts

Showing posts with the label visual-tree

Find the ScrollViewer which contains a Canvas froom within the Canvas instance

Image
Clash Royale CLAN TAG #URR8PPP Find the ScrollViewer which contains a Canvas froom within the Canvas instance I have a class which extends Canvas in WPF. Canvas This class is placed in a ScrollViewer . ScrollViewer Without passing a specific reference to the ScrollViewer into the Canvas , I want to find the ScrollViewer which contains the Canvas from within the Canvas itself. ScrollViewer Canvas ScrollViewer Canvas Canvas The Parent property of the class which extends Canvas is null , and every attempt to use the VisualTreeHelper just returns null as well. Parent Canvas null VisualTreeHelper null Is this possible to achieve? Example Code: cs - public class ExtendedCanvas:Canvas { //I wish to automatically populate this scroll viewer //reference to the instance of the scrollviwer which contains //this ExtendedCanvas instance private ScrollViewer _containingScrollViewer = null; } xaml - <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalS...