请告诉我如何在Hubsection * DataTemplate *中访问flipview控件*
解决方法
我不知道你是否设法解决你的问题.如果你不在这里是怎么回事
@H_301_6@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;
}
用法非常简单,例如在我的情况下
@H_301_6@ComboBox cb= FindChildControl<ComboBox>(HUB_HC,"SemanaHC") as ComboBox;其中HUB_HC是我的HubSection名称,而SemanaHC是HubSection中的一个组合框,也是StackPanel内部的一个.它适用于我,使用起来很简单
参考:How to access a Control inside the data template in C# Metro UI in the code behind