wpfmvvmmvvm-lightviewboxvisualtreehelper

WPF ViewBox blocks VisualTreeHelper search


I have tried this Navigation Service approach (View First) for MVVM-Light WPF https://stackoverflow.com/a/28968560/5272185

I realized that the VisualTreeHelper search for the Frame element does not find the Frame if the Frame is located inside a ViewBox.

Is there a good explanation of such strange behaviour? Is it possible to work around it?


Solution

  • It turned out that the example code in the link was the problem. If you run into this type of problem I recommend to read the following from Josh Smith Understanding the Visual Tree and Logical Tree in WPF

    The code he provides in the Research Tool project successfully found the ContentControl also when it is inside a ViewBox. I modified his code to return the content control. Problem solved.