1
感謝上一個問題(Previous Question)的答案,現在我有一個導航WPF製表位的代碼體(如下所示)。除第一個製表符之外,它工作正常。調用this.MoveFocus(... First),然後調用FocusManager.GetFocusedElement返回null。有任何想法嗎?我如何在窗口中獲得第一個製表符?找到第一個WPF製表位
謝謝, 邁克 -
// 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;
}