ViewBox阻止VisualTreeHelper搜索

ViewBox阻止VisualTreeHelper搜索

本文介绍了WPF ViewBox阻止VisualTreeHelper搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了针对MVVM-Light WPF的这种导航服务方法(首先查看) https://stackoverflow.com/a/28968560/5272185

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

我意识到,如果Frame位于ViewBox内,则VisualTreeHelper搜索Frame元素不会找到Frame.

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?

推荐答案

原来,链接中的示例代码是问题所在.如果您遇到此类问题,建议您阅读Josh Smith的以下文章了解其中的可视树和逻辑树WPF

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 SmithUnderstanding the Visual Tree and Logical Tree in WPF

他在研究工具项目中提供的代码成功找到 ContentControl也位于ViewBox内时.我修改了他的代码以返回内容控件.问题解决了.

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.

这篇关于WPF ViewBox阻止VisualTreeHelper搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:09