感谢对上一个问题(上一个问题)的回答,我现在有一段代码可以导航 WPF 制表位(如下所示)。除了第一个制表位外,它工作正常。调用 this.MoveFocus(...First) 后跟 FocusManager.GetFocusedElement 返回 null。有任何想法吗?如何在我的窗口中获得第一个制表位?
谢谢, - 迈克
// Select the first element in the window
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
TraversalRequest next = new TraversalRequest(FocusNavigationDirection.Next);
List<IInputElement> elements = new List<IInputElement>();
// Get the current element.
UIElement currentElement = FocusManager.GetFocusedElement(this) as UIElement;
while (currentElement != null)
{
elements.Add(currentElement);
// Get the next element.
currentElement.MoveFocus(next);
currentElement = FocusManager.GetFocusedElement(this) as UIElement;
// If we looped (If that is possible), exit.
if (elements[0] == currentElement)
break;
}