我知道怎么做 集 将焦点移至 Tab 键顺序中的下一个控件,但我实际上并不想更改焦点...我只想 获取 Tab 键顺序中的下一个控件(也许也可以获取上一个、第一个和最后一个控件。)那么... howyadodat?
米
最佳答案
PredictFocus(FocusNavigationDirection.Next)
不像@Cameron 所说的那样工作。我基于@Randolpho 帖子的包装器代码现在运行良好。
我尝试了几种模式,最后得出结论我必须确保container
实际上是e
的 parent 之一以免出现意外结果。
/// <summary>
/// Get next tab order element.
/// </summary>
/// <param name="e">The element to get next tab order</param>
/// <param name="container">The container element owning 'e'. Make sure this is a container of 'e'.</param>
/// <param name="goDownOnly">True if search only itself and inside of 'container'; otherwise false.
/// If true and next tab order element is outside of 'container', result in null.</param>
/// <returns>Next tab order element or null if not found</returns>
public DependencyObject GetNextTab(DependencyObject e, DependencyObject container, bool goDownOnly)
{
var navigation = typeof(FrameworkElement)
.GetProperty("KeyboardNavigation", BindingFlags.NonPublic | BindingFlags.Static)
.GetValue(null);
var method = navigation
.GetType()
.GetMethod("GetNextTab", BindingFlags.NonPublic | BindingFlags.Instance);
return method.Invoke(navigation, new object[] { e, container, goDownOnly }) as DependencyObject;
}
前任。)
var nextElement = GetNextTab(textbox1, window, false);
关于wpf - 在wpf中,如何获得tab顺序中的下一个控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5756448/