如何访问任何控制Hubsection的DataTemplate里在Windows 8.1存储 [英] How to access any control inside Hubsection Datatemplate in Windows 8.1 store

查看:123
本文介绍了如何访问任何控制Hubsection的DataTemplate里在Windows 8.1存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何内部访问flipview控制的 Hubsection *的的DataTemplate 的*


解决方案

我不知道,如果你设法已经解决您的问题。如果你没有在这里是如何

 私人的DependencyObject FindChildControl< T>(DependencyObject的控制,串ctrlName)
{
INT childNumber = VisualTreeHelper.GetChildrenCount(对照组);
的for(int i = 0; I< childNumber;我++)
{
DependencyObject的孩子= VisualTreeHelper.GetChild(控制,I);
FrameworkElement的FE =孩子一样FrameworkElement的;
//不是一个框架元素或为null
如果(FE == NULL)返回NULL;

如果(孩子是T&放大器;&安培; fe.Name == ctrlName)
{
//找到了控制,因此返回
返回子女;
}
,否则
{
//没有找到它 - 搜索儿童
的DependencyObject nextLevel = FindChildControl< T>(儿童,ctrlName);
如果(nextLevel!= NULL)
返回nextLevel;
}
}
返回NULL;
}



用法很简单,比如在我的情况

 组合框CB = FindChildControl<&组合框GT;(HUB_HCSemanaHC)作为组合框; 



在哪里HUB_HC我HubSection名和SemanaHC是HubSection女巫内的组合框也是StackPanel的内。它为我和它的简单易用



参考:的如何访问在C#中的Metro UI数据模板内部控制背后 <代码/ p>

Please tell me how to access flipview control inside Hubsection *DataTemplate*

解决方案

I don't know if you managed to solve your problem already. If you didn't here is how.

private DependencyObject FindChildControl<T>(DependencyObject control, string ctrlName)
    {
        int childNumber = VisualTreeHelper.GetChildrenCount(control);
        for (int i = 0; i < childNumber; i++)
        {
            DependencyObject child = VisualTreeHelper.GetChild(control, i);
            FrameworkElement fe = child as FrameworkElement;
            // Not a framework element or is null
            if (fe == null) return null;

            if (child is T && fe.Name == ctrlName)
            {
                // Found the control so return
                return child;
            }
            else
            {
                // Not found it - search children
                DependencyObject nextLevel = FindChildControl<T>(child, ctrlName);
                if (nextLevel != null)
                    return nextLevel;
            }
        }
        return null;
    }

usage is very simple, for example in my case

ComboBox cb= FindChildControl<ComboBox>(HUB_HC, "SemanaHC") as ComboBox;

Where HUB_HC is my HubSection name and SemanaHC is a combobox inside that HubSection witch is also inside of a StackPanel. It works for me and it's simple to use

Reference: How to access a Control inside the data template in C# Metro UI in the code behind

这篇关于如何访问任何控制Hubsection的DataTemplate里在Windows 8.1存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆