小智 12

我不知道你是否已经设法解决了你的问题.如果你没有这里是如何.

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;
    }
Run Code Online (Sandbox Code Playgroud)

用法非常简单,例如在我的情况下

ComboBox cb= FindChildControl<ComboBox>(HUB_HC, "SemanaHC") as ComboBox;
Run Code Online (Sandbox Code Playgroud)

其中HUB_HC是我的HubSection名称,而SemanaHC是一个组合框,其中HubSection女巫也在StackPanel内.它适用于我,它使用简单

参考:如何在后面的代码中访问C#Metro UI中的数据模板内的Control


小智 4

处理此问题的最佳方法是在 DataTemplate 中拥有一个用户控件。UserControl 将具有 Flipview,因此您可以轻松访问那里的 Flipview。