-->

WPF ViewBox blocks VisualTreeHelper search

2019-08-21 00:50发布

问题:

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?

回答1:

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.