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

The name of the pictureThe name of the pictureThe name of the pictureClash 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" HorizontalScrollBarVisibility="Auto" >
<local:ExtendedCanvas x:Name="extendedCanvas" />
</ScrollViewer>





Perhaps the person who downvoted this could suggest what I could add to make this a more acceptable question?
– Alex
36 secs ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived