The keyboard selection code in a TreeView is ugly as a mutha... I was trying to implement proper multi-selection and the keyboard navigation code is just not very expandable.
I ended up calling a non-public method that served as a decent entry point:
private delegate DependencyObject PredictFocusedElement(DependencyObject sourceElement, FocusNavigationDirection direction, bool treeViewNavigation, bool considerDescendants);
// get the default KeyboardNavigation instance
KeyboardNavigation keyboardNavigation = (KeyboardNavigation)typeof(FrameworkElement).GetProperty("KeyboardNavigation", BindingFlags.NonPublic | BindingFlags.Static).GetMethod.Invoke(null, null);
// create a delegate for the PredictFocusedElement method
_predictFocusedElement = (PredictFocusedElement)typeof(KeyboardNavigation).GetMethod("PredictFocusedElement", BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder,
new Type[] { typeof(DependencyObject), typeof(FocusNavigationDirection), typeof(bool), typeof(bool) },
null).CreateDelegate(typeof(PredictFocusedElement), keyboardNavigation);
Now, once you have that delegate, you can control the focus:
tvi = (TreeViewItemEx)_predictFocusedElement(tvi, FocusNavigationDirection.Down, true, true);
tvi.Focus();
If you want to see ugly code, you can look at that PredictFocusedElement code in ILSpy or whatever :).