È possibile farlo con la chiamata MoveFocus. È possibile ottenere l'oggetto attualmente focalizzato attraverso il FocusManager. Il seguente codice eseguirà l'iterazione di tutti gli oggetti nella finestra e li aggiungerà a un elenco. Si noti che questo modificherà fisicamente la finestra passando alla messa a fuoco. Molto probabilmente il codice non funzionerà se la finestra non è attiva.
// 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;
}
fonte
2009-04-30 22:48:58
geniale, grazie mille! – lamarmora