如何使用wpf从TabItem或TabControl中的TabItem本身获取控件/ UIElements?

时间:2017-09-11 02:39:08

标签: wpf

我有一个使用MVVM Wpf c#的tabcontrol。现在,我希望在活动tabitem时默认焦点控制,但在移动选项卡时它不会失去焦点。 我使用了实时可视树但没有活动,因为参数是viewmodel。我已经使用FocusManger获得了控制焦点,因此我需要从tabItem本身获取控件/ UI。

你能帮助我吗?谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用此方法递归获取所有逻辑子项:

private void GetAllChildren(DependencyObject parent, List<DependencyObject> allChildren)
{
    var children = LogicalTreeHelper.GetChildren(parent);

    foreach (var child in children.OfType<DependencyObject>())
    {
        allChildren.Add(child);
        GetAllChildren(child, allChildren);
    }
}
相关问题