首页新闻找找看学习计划

wp怎么获取Template中的控件名webview1

0
悬赏园豆:20 [待解决问题]

<Hub>

 <HubSection  Header="学生计划">
                <HubSection.ContentTemplate>
                    <DataTemplate>
                        <ScrollViewer>
                            <StackPanel>
                                <WebView Name="webview1"></WebView>
                            </StackPanel>
                        </ScrollViewer>
                    </DataTemplate>
                </HubSection.ContentTemplate>

</HubSection>

</Hub>

Agr灰灰的主页 Agr灰灰 | 初学一级 | 园豆:181
提问于:2015-06-29 16:41
< >
分享
所有回答(1)
1

可以通过视觉树遍历的方式来查找,类似的辅助类如:visualTreeHelper

例如下面这段代码,就是我以前pro使用过的:

  public static Visual FindDescendantByName(Visual element, string name)
        {
            if (element == null)
            {
                return null;
            }
            if (element is FrameworkElement && (element as FrameworkElement).Name == name)
            {
                return element;
            }
            Visual visual = null;
            if (element is FrameworkElement)
            {
                (element as FrameworkElement).ApplyTemplate();
            }
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
            {
                Visual element2 = VisualTreeHelper.GetChild(element, i) as Visual;
                visual = VisualTreeHelperEx.FindDescendantByName(element2, name);
                if (visual != null)
                {
                    break;
                }
            }
            return visual;
        }
visonme | 园豆:1674 (小虾三级) | 2015-06-30 09:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册